﻿using Commonality.DAL.MySQL;
using Commonality.DAL.WZS_SFCS;
using Commonality.Model;
using Commonality.Model.Classify;
using Commonality.Model.PLCControl;
using Commonality.Model.ScanningGunModel;
using Merge.BLL.Cave;
using Merge.Model;
using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Threading;


namespace Merge.BLL
{
    public static class MergeAutoMain
    {
        public static bool ThisClose;
        private static bool AutoFlag = false;
        public static CaverForm.CaverForm caverForm;
        
        public static void MergeStart()
        {
            ThisClose = false;           
            SFCSInterface.SFCSInterfaceInit();
            SFCSDataDispose.SFCSDataDisposeInit();
            SG.SGInit();

            //EffectiveClassGudge.EffectiveClassGudgeInit();
            
            
            PLC.InitPLCCell();
            Caver.CaverInit();
            PLC.PLCInit(AutoMainLoop_);

            caverForm = new CaverForm.CaverForm();

        }
        public static void MergeStop()
        {
            Caver.CaverStop();
            PLC.PLCClose();
        }

        #region 轮询方法

        //主线
        private static void AutoMainLoop_()
        {
            if (!AutoFlag)
            {
                Caver.CaverSelfInspection();
                Caver.CaverRuning();
                AutoFlag = true;

            }
            else
            {
                Caver.CaverLoopCom();


                AutoFuncion.ClassifyEntranceASG();



                AutoFuncion.ClassifyEntranceBSG();
                AutoFuncion.ClassifyCaveSGA1();
                AutoFuncion.ClassifyCaveSGB1();
                AutoFuncion.ClassifyCaveSGA2();
                AutoFuncion.ClassifyCaveSGB2();
                AutoFuncion.ClassifyCaveSGA3();
                AutoFuncion.ClassifyCaveSGB3();


                //AreaAAction();
                //AreaBAction();

                IAsyncResult AreaAActionAsyRes = AreaAAction.BeginInvoke(null, null);
                IAsyncResult AreaBActionAsyRes = AreaBAction.BeginInvoke(null, null);


                //AutoFuncion.ClassifyCaveSG1PutStorage();
                //AutoFuncion.ClassifyCaveSG2PutStorage();
                //AutoFuncion.ClassifyCaveSG3PutStorage();


                AutoFuncion.ClassifyExitSG();
                //AutoFuncion.ClassifyExitQRCodeDispose();
                //IAsyncResult ClassifyExitSGAsyRes = AutoFuncion.ClassifyExitQRCodeDisposeAction.BeginInvoke(null, null);

                AutoFuncion.BackflowExitSG();
                //AutoFuncion.BackflowExitQRCodeDispose();
                //IAsyncResult BackflowExitSGAsyRes =  AutoFuncion.BackflowExitQRCodeDisposeAction.BeginInvoke(null, null);



                //等待完成
                //AutoFuncion.BackflowExitQRCodeDisposeAction.EndInvoke(BackflowExitSGAsyRes);
                //AutoFuncion.ClassifyExitQRCodeDisposeAction.EndInvoke(ClassifyExitSGAsyRes);
                AreaAAction.EndInvoke(AreaAActionAsyRes);
                AreaBAction.EndInvoke(AreaBActionAsyRes);


                AutoFuncion.ThisOff();

            }
        }
        #region A/B区
        private static Action AreaAAction = () =>
        {
            Caver.CaverLoopA();
            //AutoFuncion.ClassifyEntranceQRCodeADispose();
            //AutoFuncion.ClassifyCaveSGA1QRCodeDispose();
            //AutoFuncion.ClassifyCaveSGA2QRCodeDispose();
            //AutoFuncion.ClassifyCaveSGA3QRCodeDispose();
        };


        private static Action AreaBAction = () =>
        {
            Caver.CaverLoopB();
            AutoFuncion.ClassifyEntranceQRCodeBDispose();
            AutoFuncion.ClassifyCaveSGB1QRCodeDispose();
            AutoFuncion.ClassifyCaveSGB2QRCodeDispose();
            AutoFuncion.ClassifyCaveSGB3QRCodeDispose();
        };
        #endregion

        #endregion 轮询方法
    }

    public static class AutoFuncion
    {
        public static void AutoFuncionInit()
        {
            CaverA1Scalar_Flag = 0;
            CaverA2Scalar_Flag = 0;
            CaverA3Scalar_Flag = 0;
            CaverB1Scalar_Flag = 0;
            CaverB2Scalar_Flag = 0;
            CaverB3Scalar_Flag = 0;

            CaverA1Target = 0;
            CaverA2Target = 0;
            CaverA3Target = 0;

            CaverA1SN_Flag = new Tuple<string, string>("", "");
            CaverA2SN_Flag = new Tuple<string, string>("", "");
            CaverA3SN_Flag = new Tuple<string, string>("", "");
            CaverB1SN_Flag = new Tuple<string, string>("", "");
            CaverB2SN_Flag = new Tuple<string, string>("", "");
            CaverB3SN_Flag = new Tuple<string, string>("", "");

            CaverA1Eigenvector_Flag = new CEigenvector(LINE.ZERO, "", KCAndBF.ZERO, Remark.ZERO);
            CaverA2Eigenvector_Flag = new CEigenvector(LINE.ZERO, "", KCAndBF.ZERO, Remark.ZERO);
            CaverA3Eigenvector_Flag = new CEigenvector(LINE.ZERO, "", KCAndBF.ZERO, Remark.ZERO);
            CaverB1Eigenvector_Flag = new CEigenvector(LINE.ZERO, "", KCAndBF.ZERO, Remark.ZERO);
            CaverB2Eigenvector_Flag = new CEigenvector(LINE.ZERO, "", KCAndBF.ZERO, Remark.ZERO);
            CaverB3Eigenvector_Flag = new CEigenvector(LINE.ZERO, "", KCAndBF.ZERO, Remark.ZERO);
        }

        #region 标志/状态

        /// <summary>
        /// A1结点状态
        /// </summary>
        public static byte CaverA1Scalar_Flag;

        public static bool CaverA1Scalar_FlagT;

        /// <summary>
        /// 轴目标
        /// </summary>
        private static short CaverA1Target = 0;

        public static byte CaverA2Scalar_Flag;
        public static bool CaverA2Scalar_FlagT;

        /// <summary>
        /// 轴目标
        /// </summary>
        private static short CaverA2Target = 0;

        public static byte CaverA3Scalar_Flag;
        public static bool CaverA3Scalar_FlagT;

        /// <summary>
        /// 轴目标
        /// </summary>
        private static short CaverA3Target = 0;

        private static byte CaverB1Scalar_Flag;
        private static byte CaverB2Scalar_Flag;
        private static byte CaverB3Scalar_Flag;
        public static bool CaverB1Scalar_FlagT;
        public static bool CaverB2Scalar_FlagT;
        public static bool CaverB3Scalar_FlagT;

        /// <summary>
        /// 轴目标
        /// </summary>
        private static short CaverB1Target = 0;

        /// <summary>
        /// 轴目标
        /// </summary>
        private static short CaverB2Target = 0;

        /// <summary>
        /// 轴目标
        /// </summary>
        private static short CaverB3Target = 0;

        /// <summary>
        /// A1结点SN交接变量
        /// </summary>
        private static Tuple<string, string> CaverA1SN_Flag;

        private static Tuple<string, string> CaverA2SN_Flag;
        private static Tuple<string, string> CaverA3SN_Flag;
        private static Tuple<string, string> CaverB1SN_Flag;
        private static Tuple<string, string> CaverB2SN_Flag;
        private static Tuple<string, string> CaverB3SN_Flag;

        /// <summary>
        /// A1结点特征交接
        /// </summary>
        private static CEigenvector CaverA1Eigenvector_Flag;

        private static CEigenvector CaverA2Eigenvector_Flag;
        private static CEigenvector CaverA3Eigenvector_Flag;
        private static CEigenvector CaverB1Eigenvector_Flag;
        private static CEigenvector CaverB2Eigenvector_Flag;
        private static CEigenvector CaverB3Eigenvector_Flag;

        #endregion 标志/状态

        #region 分类区入口

        /// <summary>
        /// 分类区入口结点扫码
        /// </summary>
        public static void ClassifyEntranceASG()
        {
            //A
            if (CPLCControl.LAD_GetDblCell_(PLC.dClassifyEntrance_SQRC_A) == 1 && !SG.EntranceSGAing)
            {
                SG.EntranceSGACRCode = "";
                SG.EntranceSGAAction.BeginInvoke(null, null);
                SG.EntranceSGAing = true;
                Log4Net.MsgInfo("A侧分类区入口-结点扫码");

                ClassifyEntranceQRCodeADisposeAction.BeginInvoke(null, null);
            }

            if (CPLCControl.LAD_GetDblCell_(PLC.dClassifyEntrance_SQRC_A) != 1)
            {
                SG.EntranceSGAing = false;
            }

        }
        public static void ClassifyEntranceBSG()
        {

            //B
            if (CPLCControl.LAD_GetDblCell_(PLC.dClassifyEntrance_SQRC_B) == 1 && !SG.EntranceSGBing)
            {
                SG.EntranceSGBCRCode = "";
                SG.EntranceSGBAction.BeginInvoke(null, null);
                SG.EntranceSGBing = true;
                Log4Net.MsgInfo("B侧分类区入口结-点扫码");
            }
        }
        private static Action ClassifyEntranceQRCodeADisposeAction = () => { ClassifyEntranceQRCodeADispose_(); };
        public static void ClassifyEntranceQRCodeADispose_()
        {
            //A
            if (SG.EntranceSGAing)
            {
                Thread.Sleep((int)SG.Timeout);
                #region 有效扫码-主线

                if (SG.EntranceSGACRCode.Length == SG.EffeLength)
                {
                    #region 分类区准入结点判断

                    int ori = 0;        //流向变量
                    string message = "";
                    //查询流向信息：异常摞，相机检测异常
                    MySqlFunction.PackageOrientation.PackageOrientation_SELECT(SG.EntranceSGACRCode, ref ori, ref message);
                    if (ori != 0)
                    {
                        //异常对象：流向旁路
                        CPLCControl.LAD_SetDblCell(PLC.dClassifyEntrance_SQRC_A, 3);            //异常旁路：3
                        Log4Net.MsgInfo("A侧分类区入口结点-禁入：" + SG.EntranceSGACRCode + "(" + message + ")");
                        SG.EntranceSGACRCode = "";
                        //SG.EntranceSGAing = false;
                        return;
                    }
                    else
                    {
                        CPLCControl.LAD_SetDblCell(PLC.dClassifyEntrance_SQRC_A, 2);            //
                        Log4Net.MsgInfo("A侧分类区入口结点-准入：" + SG.EntranceSGACRCode);
                    }

                    #endregion 分类区准入结点判断


                    #region 同类/空仓查询
                    CEigenvector cEigenvector = new CEigenvector(LINE.ZERO, "", KCAndBF.ZERO, Remark.ZERO);     //特征类
                    InquireEig(SG.EntranceSGACRCode, ref cEigenvector);
                    #region 同类查询
                    if (Caver.SearchClassReferenceARow1(ref cEigenvector).Count != 0)
                    {
                        //B区存在同类
                        Log4Net.MsgInfo("A区入料口-A区A1存在同类" + SG.EntranceSGACRCode);
                    }
                    else if (Caver.SearchClassReferenceARow2(ref cEigenvector).Count != 0)
                    {
                        //B区存在同类
                        Log4Net.MsgInfo("A区入料口-A区A2存在同类" + SG.EntranceSGACRCode);
                    }
                    else if (Caver.SearchClassReferenceARow3(ref cEigenvector).Count != 0)
                    {
                        //B区存在同类
                        Log4Net.MsgInfo("A区入料口-A区A3存在同类" + SG.EntranceSGACRCode);
                    }
                    #endregion
                    #region 无同类有空仓
                    #region 注册新仓位
                    else if (Caver.SearchVacancyARow2().Count != 0)
                    {
                        int num = Caver.SearchVacancyARow2()[0];
                        Log4Net.MsgInfo("入口-A2行-新类注册空仓" + num);
                        Caver.CaverModelNumber_Eigenvector(num, ref cEigenvector);
                        CaverBuffData.WriteCaverEigenvector(num, ref cEigenvector);
                    }
                    else if (Caver.SearchVacancyARow1().Count != 0)
                    {
                        int num = Caver.SearchVacancyARow1()[0];
                        Log4Net.MsgInfo("入口-A1行-新类注册空仓" + num);
                        Caver.CaverModelNumber_Eigenvector(num, ref cEigenvector);
                        CaverBuffData.WriteCaverEigenvector(num, ref cEigenvector);
                    }
                    else if (Caver.SearchVacancyARow3().Count != 0)
                    {
                        int num = Caver.SearchVacancyARow3()[0];
                        Log4Net.MsgInfo("入口-A3行-新类注册空仓" + num);
                        Caver.CaverModelNumber_Eigenvector(num, ref cEigenvector);
                        CaverBuffData.WriteCaverEigenvector(num, ref cEigenvector);
                    }

                    #endregion
                    #endregion
                    #region 区域无同类无空位
                    else
                    {
                        //B区即不存在同类也不存在空位

                        //异常对象：流向旁路
                        MySqlFunction.PackageOrientation.PackageOrientation_UPDATE(SG.EntranceSGACRCode, 0, "区域阻塞");
                        CPLCControl.LAD_SetDblCell(PLC.dClassifyEntrance_SQRC_A, 3);            //异常旁路：3
                        Log4Net.MsgInfo("A区域阻塞" + SG.EntranceSGACRCode);
                        SG.EntranceSGACRCode = "";
                        //SG.EntranceSGAing = false;
                        return;
                    }
                    #endregion

                    #endregion

                    SG.EntranceSGACRCode = "";
                    //SG.EntranceSGAing = false;
                    return;
                }

                #endregion 有效扫码-主线

                #region 扫码超时/异常

                else if (SG.EntranceSGACRCode != "")
                {
                    CPLCControl.LAD_SetDblCell(PLC.dClassifyEntrance_SQRC_A, 3);
                    Log4Net.MsgInfo("A侧分类区入口结点-扫码超时/异常");
                    SG.EntranceSGACRCode = "";
                    //SG.EntranceSGAing = false;
                }

                #endregion 扫码超时/异常
            }
        }
        /// <summary>
        /// 分类区入口结点扫码结果处理
        /// </summary>
        public static void ClassifyEntranceQRCodeADispose()
        {
            //A
            if (SG.EntranceSGAing)
            {
                #region 有效扫码-主线

                if (SG.EntranceSGACRCode.Length == SG.EffeLength)
                {
                    #region 分类区准入结点判断

                    int ori = 0;        //流向变量
                    string message = "";
                    //查询流向信息：异常摞，相机检测异常
                    MySqlFunction.PackageOrientation.PackageOrientation_SELECT(SG.EntranceSGACRCode, ref ori, ref message);
                    if (ori != 0)
                    {
                        //异常对象：流向旁路
                        CPLCControl.LAD_SetDblCell_(PLC.dClassifyEntrance_SQRC_A, 3);            //异常旁路：3
                        Log4Net.MsgInfo("A侧分类区入口结点-禁入：" + SG.EntranceSGACRCode + "(" + message + ")");
                        SG.EntranceSGACRCode = "";
                        SG.EntranceSGAing = false;
                        return;
                    }
                    else
                    {
                        CPLCControl.LAD_SetDblCell_(PLC.dClassifyEntrance_SQRC_A, 2);            //
                        Log4Net.MsgInfo("A侧分类区入口结点-准入：" + SG.EntranceSGACRCode);
                    }

                    #endregion 分类区准入结点判断


                    #region 同类/空仓查询
                    CEigenvector cEigenvector = new CEigenvector(LINE.ZERO, "", KCAndBF.ZERO, Remark.ZERO);     //特征类
                    InquireEig(SG.EntranceSGACRCode, ref cEigenvector);
                    #region 同类查询
                    if (Caver.SearchClassReferenceARow1(ref cEigenvector).Count != 0)
                    {
                        //B区存在同类
                        Log4Net.MsgInfo("A区入料口-A区A1存在同类" + SG.EntranceSGACRCode);
                    }
                    else if (Caver.SearchClassReferenceARow2(ref cEigenvector).Count != 0)
                    {
                        //B区存在同类
                        Log4Net.MsgInfo("A区入料口-A区A2存在同类" + SG.EntranceSGACRCode);
                    }
                    else if (Caver.SearchClassReferenceARow3(ref cEigenvector).Count != 0)
                    {
                        //B区存在同类
                        Log4Net.MsgInfo("A区入料口-A区A3存在同类" + SG.EntranceSGACRCode);
                    }
                    #endregion
                    #region 无同类有空仓
                    #region 注册新仓位
                    else if (Caver.SearchVacancyARow2().Count != 0)
                    {
                        int num = Caver.SearchVacancyARow2()[0];
                        Log4Net.MsgInfo("入口-A2行-新类注册空仓" + num);
                        Caver.CaverModelNumber_Eigenvector(num, ref cEigenvector);
                        CaverBuffData.WriteCaverEigenvector(num, ref cEigenvector);
                    }
                    else if (Caver.SearchVacancyARow1().Count != 0)
                    {
                        int num = Caver.SearchVacancyARow1()[0];
                        Log4Net.MsgInfo("入口-A1行-新类注册空仓" + num);
                        Caver.CaverModelNumber_Eigenvector(num, ref cEigenvector);
                        CaverBuffData.WriteCaverEigenvector(num, ref cEigenvector);
                    }
                    else if (Caver.SearchVacancyARow3().Count != 0)
                    {
                        int num = Caver.SearchVacancyARow3()[0];
                        Log4Net.MsgInfo("入口-A3行-新类注册空仓" + num);
                        Caver.CaverModelNumber_Eigenvector(num, ref cEigenvector);
                        CaverBuffData.WriteCaverEigenvector(num, ref cEigenvector);
                    }

                    #endregion
                    #endregion
                    #region 区域无同类无空位
                    else
                    {
                        //B区即不存在同类也不存在空位

                        //异常对象：流向旁路
                        MySqlFunction.PackageOrientation.PackageOrientation_UPDATE(SG.EntranceSGACRCode, 0, "区域阻塞");
                        CPLCControl.LAD_SetDblCell_(PLC.dClassifyEntrance_SQRC_A, 3);            //异常旁路：3
                        Log4Net.MsgInfo("A区域阻塞" + SG.EntranceSGACRCode);
                        SG.EntranceSGACRCode = "";
                        SG.EntranceSGAing = false;
                        return;
                    }
                    #endregion

                    #endregion

                    SG.EntranceSGACRCode = "";
                    SG.EntranceSGAing = false;
                    return;
                }

                #endregion 有效扫码-主线

                #region 扫码超时/异常

                else if (SG.EntranceSGACRCode != "")
                {
                    CPLCControl.LAD_SetDblCell_(PLC.dClassifyEntrance_SQRC_A, 3);
                    Log4Net.MsgInfo("A侧分类区入口结点-扫码超时/异常");
                    SG.EntranceSGACRCode = "";
                    SG.EntranceSGAing = false;
                }

                #endregion 扫码超时/异常
            }
        }
        public static void ClassifyEntranceQRCodeBDispose()
        {
            //B
            if (SG.EntranceSGBing)
            {
                #region 有效扫码-主线

                if (SG.EntranceSGBCRCode.Length == SG.EffeLength)
                {

                    #region 分类区准入结点判断

                    int ori = 0;        //流向变量
                    string message = "";
                    //查询流向信息：异常摞，相机检测异常
                    MySqlFunction.PackageOrientation.PackageOrientation_SELECT(SG.EntranceSGBCRCode, ref ori, ref message);
                    if (ori != 0)
                    {
                        //异常对象：流向旁路
                        CPLCControl.LAD_SetDblCell_(PLC.dClassifyEntrance_SQRC_B, 3);            //异常旁路：3
                        Log4Net.MsgInfo("B侧分类区入口结点-禁入：" + SG.EntranceSGBCRCode + "(" + message + ")");
                        SG.EntranceSGBCRCode = "";
                        SG.EntranceSGBing = false;
                        return;
                    }
                    else
                    {
                        CPLCControl.LAD_SetDblCell_(PLC.dClassifyEntrance_SQRC_B, 2);            //
                        Log4Net.MsgInfo("B侧分类区入口结点-准入：" + SG.EntranceSGBCRCode);
                    }

                    #endregion 分类区准入结点判断

                    #region 同类/空仓查询
                    CEigenvector cEigenvector = new CEigenvector(LINE.ZERO, "", KCAndBF.ZERO, Remark.ZERO);     //特征类
                    InquireEig(SG.EntranceSGBCRCode, ref cEigenvector);
                    if (/*Caver.SearchClassReferenceB(ref cEigenvector).Count != 0*/
                        Caver.SearchClassReferenceBRow1(ref cEigenvector).Count != 0 ||
                        Caver.SearchClassReferenceBRow2(ref cEigenvector).Count != 0 ||
                        Caver.SearchClassReferenceBRow3(ref cEigenvector).Count != 0)
                    {
                        //B区存在同类
                        Log4Net.MsgInfo("B区入料口-B区存在同类" + SG.EntranceSGBCRCode);

                    }
                    else if (Caver.SearchVacancyBRow1().Count != 0 || Caver.SearchVacancyBRow2().Count != 0 || Caver.SearchVacancyBRow3().Count != 0)
                    {
                        //B区不存在同类存在空位
                        Log4Net.MsgInfo("B区入料口-B区存在空位" + SG.EntranceSGBCRCode);

                        #region 注册新仓位
                        //if (Caver.SearchVacancyBRow1().Count != 0)
                        //{
                        //    int num = Caver.SearchVacancyBRow1()[0];
                        //    Log4Net.MsgInfo("B1行-新类注册空仓" + num);
                        //    Caver.CaverModelNumber_Eigenvector(num, ref cEigenvector);
                        //    CaverBuffData.WriteCaverEigenvector(num, ref cEigenvector);
                        //}
                        //else if (Caver.SearchVacancyBRow2().Count != 0)
                        //{
                        //    int num = Caver.SearchVacancyBRow2()[0];
                        //    Log4Net.MsgInfo("B2行-新类注册空仓" + num);
                        //    Caver.CaverModelNumber_Eigenvector(num, ref cEigenvector);
                        //    CaverBuffData.WriteCaverEigenvector(num, ref cEigenvector);
                        //}
                        //else if (Caver.SearchVacancyBRow3().Count != 0)
                        //{
                        //    int num = Caver.SearchVacancyBRow3()[0];
                        //    Log4Net.MsgInfo("B3行-新类注册空仓" + num);
                        //    Caver.CaverModelNumber_Eigenvector(num, ref cEigenvector);
                        //    CaverBuffData.WriteCaverEigenvector(num, ref cEigenvector);
                        //}


                        if (Caver.SearchVacancyBRow2().Count != 0)
                        {
                            int num = Caver.SearchVacancyBRow2()[0];
                            Log4Net.MsgInfo("入口-B2行-新类注册空仓" + num);
                            Caver.CaverModelNumber_Eigenvector(num, ref cEigenvector);
                            CaverBuffData.WriteCaverEigenvector(num, ref cEigenvector);
                        }
                        else if (Caver.SearchVacancyBRow1().Count != 0)
                        {
                            int num = Caver.SearchVacancyBRow1()[0];
                            Log4Net.MsgInfo("入口-B1行-新类注册空仓" + num);
                            Caver.CaverModelNumber_Eigenvector(num, ref cEigenvector);
                            CaverBuffData.WriteCaverEigenvector(num, ref cEigenvector);
                        }
                        else if (Caver.SearchVacancyBRow3().Count != 0)
                        {
                            int num = Caver.SearchVacancyBRow3()[0];
                            Log4Net.MsgInfo("入口-B3行-新类注册空仓" + num);
                            Caver.CaverModelNumber_Eigenvector(num, ref cEigenvector);
                            CaverBuffData.WriteCaverEigenvector(num, ref cEigenvector);
                        }
                        #endregion


                    }
                    else
                    {
                        //B区即不存在同类也不存在空位
                        //异常对象：流向旁路
                        MySqlFunction.PackageOrientation.PackageOrientation_UPDATE(SG.EntranceSGBCRCode, 0, "区域阻塞");
                        CPLCControl.LAD_SetDblCell_(PLC.dClassifyEntrance_SQRC_B, 3);            //异常旁路：3
                        Log4Net.MsgInfo("B区域阻塞" + SG.EntranceSGBCRCode);
                        SG.EntranceSGBCRCode = "";
                        SG.EntranceSGBing = false;
                        return;
                    }
                    #endregion
                    SG.EntranceSGBCRCode = "";
                    SG.EntranceSGBing = false;
                    return;
                }

                #endregion 有效扫码-主线

                #region 扫码超时/异常

                else if (SG.EntranceSGBCRCode != "")
                {
                    CPLCControl.LAD_SetDblCell_(PLC.dClassifyEntrance_SQRC_B, 3);
                    Log4Net.MsgInfo("B侧分类区入口结点-扫码超时/异常");
                    SG.EntranceSGBCRCode = "";
                    SG.EntranceSGBing = false;
                }

                #endregion 扫码超时/异常
            }
        }
        #endregion 分类区入口

        #region 分类区结点1

        /// <summary>
        /// 分类A区第一排结点扫码
        /// </summary>
        public static void ClassifyCaveSGA1()
        {
            //A
            if (CPLCControl.LAD_GetDblCell_(PLC.dCave1_A) == 1 && !SG.CaveSGA1ing)
            {
                SG.CaveSGA1Action.BeginInvoke(null, null);
                SG.CaveSGA1ing = true;
                SG.CaveSGA1QRCode = "";
                Log4Net.MsgInfo("A1结点-扫码");

                ClassifyCaveSGA1QRCodeDisposeAction.BeginInvoke(null, null);
            }

            if (CPLCControl.LAD_GetDblCell_(PLC.dCave1_A) != 1)
            {
                SG.CaveSGA1ing = false;
            }
        }
        public static void ClassifyCaveSGB1()
        {

            //B
            if (CPLCControl.LAD_GetDblCell_(PLC.dCave1_B) == 1 && !SG.CaveSGB1ing)
            {
                SG.CaveSGB1QRCode = "";
                SG.CaveSGB1Action.BeginInvoke(null, null);
                SG.CaveSGB1ing = true;
                Log4Net.MsgInfo("B1结点-扫码");
            }
        }

        static Action ClassifyCaveSGA1QRCodeDisposeAction = () => { ClassifyCaveSGA1QRCodeDispose(); };
        /// <summary>
        /// 分类A区第一排结点流向
        /// </summary>
        /// <returns></returns>
        public static void ClassifyCaveSGA1QRCodeDispose()
        {
            //A
            if (SG.CaveSGA1ing)
            {
                Thread.Sleep(900);
                #region 有效扫码-主线

                if (SG.CaveSGA1QRCode.Length == SG.EffeLength)
                {
                    try
                    {
                        string eig = "";        //特征变量
                        CEigenvector cEigenvector = new CEigenvector(LINE.ZERO, "", KCAndBF.ZERO, Remark.ZERO);     //特征类
                        MySqlFunction.TrayCellDataList.TrayCellDataList__Eigenvector_SELECT(SG.CaveSGA1QRCode, SG.CaveSGA1QRCode, ref eig);         //查询特征
                        if (eig == "")
                        {
                            Log4Net.MsgInfo("A1结点-特征索引为空");
                            CPLCControl.LAD_SetDblCell(PLC.dCave1_A, 3);
                            SG.CaveSGA1QRCode = "";
                            //SG.CaveSGA1ing = false;
                            return;
                        }
                        Log4Net.MsgInfo("A1结点-特征索引" + eig);

                        string snb = "";
                        MySqlFunction.TrayCellDataList.TrayCellDataList_SN_SELECT(SG.CaveSGA1QRCode, ref snb);          //使用tray中一个sn由数据库索引另外一个sn
                        CaverA1SN_Flag = new Tuple<string, string>(SG.CaveSGA1QRCode, snb);

                        //TODU:首行分配方法
                        CEigenvector.EigenvectorString2C(eig, ref cEigenvector);            //字符串转特征类
                        CaverA1Eigenvector_Flag = new CEigenvector(cEigenvector.LINEi, cEigenvector.PN, cEigenvector.KCAndBF, cEigenvector.Remark);
                        bool flah = false;
                        CaverA1Scalar_Flag = ArrangeA1(ref cEigenvector, ref SG.CaveSGA1QRCode, ref snb, ref flah);
                        Log4Net.MsgInfo("A1行-仓位分配");
                    }
                    catch (Exception)
                    {
                        Log4Net.MsgInfo("A1结点-特征索引为空");
                        CPLCControl.LAD_SetDblCell(PLC.dCave1_A, 3);
                        SG.CaveSGA1QRCode = "";
                        //SG.CaveSGA1ing = false;
                        return;
                    }
                }

                #endregion 有效扫码-主线

                #region 码异常

                else if (SG.CaveSGA1QRCode != "")
                {
                    Log4Net.MsgInfo("A1结点-扫码异常");
                    CPLCControl.LAD_SetDblCell(PLC.dCave1_A, 3);
                    SG.CaveSGA1QRCode = "";
                    //SG.CaveSGA1ing = false;
                    return;
                }

                #endregion 码异常
            }

        }
        public static void ClassifyCaveSGB1QRCodeDispose()
        {
            //B
            if (SG.CaveSGB1ing)
            {
                #region 有效扫码-主线

                if (SG.CaveSGB1QRCode.Length == SG.EffeLength)
                {
                    try
                    {
                        string eig = "";        //特征变量
                        CEigenvector cEigenvector = new CEigenvector(LINE.ZERO, "", KCAndBF.ZERO, Remark.ZERO);     //特征类
                        MySqlFunction.TrayCellDataList.TrayCellDataList__Eigenvector_SELECT(SG.CaveSGB1QRCode, SG.CaveSGB1QRCode, ref eig);         //查询特征
                        if (eig == "")
                        {
                            Log4Net.MsgInfo("B1结点-特征索引为空");
                            CPLCControl.LAD_SetDblCell_(PLC.dCave1_B, 3);
                            SG.CaveSGB1QRCode = "";
                            SG.CaveSGB1ing = false;
                            return;
                        }
                        Log4Net.MsgInfo("B1结点-特征索引" + eig);

                        string snb = "";
                        MySqlFunction.TrayCellDataList.TrayCellDataList_SN_SELECT(SG.CaveSGB1QRCode, ref snb);          //使用tray中一个sn由数据库索引另外一个sn
                        CaverB1SN_Flag = new Tuple<string, string>(SG.CaveSGB1QRCode, snb);

                        //TODU:首行分配方法
                        CEigenvector.EigenvectorString2C(eig, ref cEigenvector);            //字符串转特征类
                        CaverB1Eigenvector_Flag = new CEigenvector(cEigenvector.LINEi, cEigenvector.PN, cEigenvector.KCAndBF, cEigenvector.Remark);
                        CaverB1Scalar_Flag = ArrangeB1(ref cEigenvector, ref SG.CaveSGB1QRCode, ref snb, ref SG.CaveSGB1ing);
                        Log4Net.MsgInfo("B1行-仓位分配");
                    }
                    catch (Exception)
                    {
                        Log4Net.MsgInfo("B1结点-特征索引为空");
                        CPLCControl.LAD_SetDblCell_(PLC.dCave1_B, 3);
                        SG.CaveSGB1QRCode = "";
                        SG.CaveSGB1ing = false;
                        return;
                    }
                }

                #endregion 有效扫码-主线

                #region 码异常

                else if (SG.CaveSGB1QRCode != "")
                {
                    Log4Net.MsgInfo("B1结点-扫码异常");
                    CPLCControl.LAD_SetDblCell_(PLC.dCave1_B, 3);
                    SG.CaveSGB1QRCode = "";
                    SG.CaveSGB1ing = false;
                    return;
                }

                #endregion 码异常
            }
        }


        public static void ClassifyCaveSG1PutStorage()
        {
            //A
            if (CPLCControl.LAD_GetDblCell_(PLC.dCave1_A) == 4)
            {
                Log4Net.MsgInfo("A1结点-顶升完成");

                switch (CaverA1Scalar_Flag)
                {
                    case 1:
                        //同类入仓
                        Log4Net.MsgInfo("A1行-入仓操作");
                        Caver.CaverModelNumber_ProgrammeWarehousing(Caver.SearchClassReferenceARow1(ref CaverA1Eigenvector_Flag)[0], CaverA1SN_Flag.Item1, CaverA1SN_Flag.Item2, ref CaverA1Scalar_Flag);

                        break;

                    case 2:
                        //空仓入仓
                        Caver.CaverModelNumber_ProgrammeWarehousing(CaverA1Target, CaverA1SN_Flag.Item1, CaverA1SN_Flag.Item2, ref CaverA1Scalar_Flag);

                        break;

                    default:

                        break;
                }
            }

            //B
            if (CPLCControl.LAD_GetDblCell_(PLC.dCave1_B) == 4)
            {
                Log4Net.MsgInfo("B1结点-顶升完成");

                switch (CaverB1Scalar_Flag)
                {
                    case 1:
                        //同类入仓
                        Log4Net.MsgInfo("B1行-入仓操作");
                        Caver.CaverModelNumber_ProgrammeWarehousing(Caver.SearchClassReferenceBRow1(ref CaverB1Eigenvector_Flag)[0], CaverB1SN_Flag.Item1, CaverB1SN_Flag.Item2, ref CaverB1Scalar_Flag);

                        break;

                    case 2:
                        //空仓入仓
                        Caver.CaverModelNumber_ProgrammeWarehousing(CaverB1Target, CaverB1SN_Flag.Item1, CaverB1SN_Flag.Item2, ref CaverB1Scalar_Flag);

                        break;

                    default:

                        break;
                }
            }
        }


        #endregion 分类区结点1

        #region 分类区结点2

        public static void ClassifyCaveSGA2()
        {
            //A
            if (CPLCControl.LAD_GetDblCell_(PLC.dCave2_A) == 1 && !SG.CaveSGA2ing)
            {
                SG.CaveSGA2QRCode = "";
                SG.CaveSGA2Action.BeginInvoke(null, null);
                SG.CaveSGA2ing = true;
                Log4Net.MsgInfo("A2结点-扫码");

                ClassifyCaveSGA2QRCodeDisposeAction.BeginInvoke(null, null);
            }

            if (CPLCControl.LAD_GetDblCell_(PLC.dCave2_A) != 1)
            {
                SG.CaveSGA2ing = false;
            }

        }
        public static void ClassifyCaveSGB2()
        {
            //B
            if (CPLCControl.LAD_GetDblCell_(PLC.dCave2_B) == 1 && !SG.CaveSGB2ing)
            {
                SG.CaveSGB2QRCode = "";
                SG.CaveSGB2Action.BeginInvoke(null, null);
                SG.CaveSGB2ing = true;
                Log4Net.MsgInfo("B2结点-扫码");
            }
        }
        private static Action ClassifyCaveSGA2QRCodeDisposeAction = () => { ClassifyCaveSGA2QRCodeDispose(); };
        public static void ClassifyCaveSGA2QRCodeDispose()
        {
            //A
            if (SG.CaveSGA2ing)
            {
                Thread.Sleep(900);
                #region 有效扫码-主线

                if (SG.CaveSGA2QRCode.Length == SG.EffeLength)
                {
                    try
                    {
                        string eig = "";
                        CEigenvector cEigenvector = new CEigenvector(LINE.ZERO, "", KCAndBF.ZERO, Remark.ZERO);
                        MySqlFunction.TrayCellDataList.TrayCellDataList__Eigenvector_SELECT(SG.CaveSGA2QRCode, SG.CaveSGA2QRCode, ref eig);         //查询特征
                        if (eig == "")
                        {
                            Log4Net.MsgInfo("A2结点-特征索引为空");
                            CPLCControl.LAD_SetDblCell(PLC.dCave2_A, 3);
                            SG.CaveSGA2QRCode = "";
                            //SG.CaveSGA2ing = false;
                            return;
                        }
                        Log4Net.MsgInfo("A2结点-特征索引" + eig);

                        string snb = "";
                        MySqlFunction.TrayCellDataList.TrayCellDataList_SN_SELECT(SG.CaveSGA2QRCode, ref snb);          //使用tray中一个sn由数据库索引另外一个sn
                        CaverA2SN_Flag = new Tuple<string, string>(SG.CaveSGA2QRCode, snb);

                        //TODU:首行分配方法
                        CEigenvector.EigenvectorString2C(eig, ref cEigenvector);            //字符串转特征类
                        CaverA2Eigenvector_Flag = new CEigenvector(cEigenvector.LINEi, cEigenvector.PN, cEigenvector.KCAndBF, cEigenvector.Remark);
                        bool flag = false;
                        CaverA2Scalar_Flag = ArrangeA2(ref cEigenvector, ref SG.CaveSGA2QRCode, ref snb, ref flag);
                        Log4Net.MsgInfo("A2行-仓位分配");
                    }
                    catch (Exception)
                    {
                        Log4Net.MsgInfo("A2结点-扫码异常");
                        CPLCControl.LAD_SetDblCell(PLC.dCave2_A, 3);
                        SG.CaveSGA2QRCode = "";
                        //SG.CaveSGA2ing = false;
                        return;
                    }
                }

                #endregion 有效扫码-主线

                #region 码异常

                else if (SG.CaveSGA2QRCode != "")
                {
                    Log4Net.MsgInfo("A2结点-扫码异常");
                    CPLCControl.LAD_SetDblCell(PLC.dCave2_A, 3);
                    SG.CaveSGA2QRCode = "";
                    //SG.CaveSGA2ing = false;
                    return;
                }

                #endregion 码异常
            }

        }
        public static void ClassifyCaveSGB2QRCodeDispose()
        {
            //B
            if (SG.CaveSGB2ing)
            {
                #region 有效扫码-主线

                if (SG.CaveSGB2QRCode.Length == SG.EffeLength)
                {
                    try
                    {
                        string eig = "";
                        CEigenvector cEigenvector = new CEigenvector(LINE.ZERO, "", KCAndBF.ZERO, Remark.ZERO);
                        MySqlFunction.TrayCellDataList.TrayCellDataList__Eigenvector_SELECT(SG.CaveSGB2QRCode, SG.CaveSGB2QRCode, ref eig);         //查询特征
                        if (eig == "")
                        {
                            Log4Net.MsgInfo("B2结点-特征索引为空");
                            CPLCControl.LAD_SetDblCell_(PLC.dCave2_B, 3);
                            SG.CaveSGB2QRCode = "";
                            SG.CaveSGB2ing = false;
                            return;
                        }
                        Log4Net.MsgInfo("B2结点-特征索引" + eig);

                        string snb = "";
                        MySqlFunction.TrayCellDataList.TrayCellDataList_SN_SELECT(SG.CaveSGB2QRCode, ref snb);          //使用tray中一个sn由数据库索引另外一个sn
                        CaverB2SN_Flag = new Tuple<string, string>(SG.CaveSGB2QRCode, snb);

                        //TODU:首行分配方法
                        CEigenvector.EigenvectorString2C(eig, ref cEigenvector);            //字符串转特征类
                        CaverB2Eigenvector_Flag = new CEigenvector(cEigenvector.LINEi, cEigenvector.PN, cEigenvector.KCAndBF, cEigenvector.Remark);
                        CaverB2Scalar_Flag = ArrangeB2(ref cEigenvector, ref SG.CaveSGB2QRCode, ref snb, ref SG.CaveSGB2ing);
                        Log4Net.MsgInfo("B2行-仓位分配");
                    }
                    catch (Exception)
                    {
                        Log4Net.MsgInfo("B2结点-扫码异常");
                        CPLCControl.LAD_SetDblCell_(PLC.dCave2_B, 3);
                        SG.CaveSGB2QRCode = "";
                        SG.CaveSGB2ing = false;
                        return;
                    }
                }

                #endregion 有效扫码-主线

                #region 码异常

                else if (SG.CaveSGB2QRCode != "")
                {
                    Log4Net.MsgInfo("B2结点-扫码异常");
                    CPLCControl.LAD_SetDblCell_(PLC.dCave2_B, 3);
                    SG.CaveSGB2QRCode = "";
                    SG.CaveSGB2ing = false;
                    return;
                }

                #endregion 码异常
            }
        }

        public static void ClassifyCaveSG2PutStorage()
        {
            if (CPLCControl.LAD_GetDblCell_(PLC.dCave2_A) == 4)
            {
                Log4Net.MsgInfo("A2结点-顶升完成");
                switch (CaverA2Scalar_Flag)
                {
                    case 1:
                        //同类入仓
                        Log4Net.MsgInfo("A2行-入仓操作");
                        Caver.CaverModelNumber_ProgrammeWarehousing(Caver.SearchClassReferenceARow2(ref CaverA2Eigenvector_Flag)[0], CaverA2SN_Flag.Item1, CaverA2SN_Flag.Item2,ref CaverA2Scalar_Flag);

                        break;

                    case 2:
                        //空仓入仓
                        Caver.CaverModelNumber_ProgrammeWarehousing(Caver.SearchVacancyARow1()[0], CaverA2SN_Flag.Item1, CaverA2SN_Flag.Item2,ref CaverA2Scalar_Flag);

                        break;

                    default:
                        break;
                }
            }

            if (CPLCControl.LAD_GetDblCell_(PLC.dCave2_B) == 4)
            {
                Log4Net.MsgInfo("B2结点-顶升完成");

                switch (CaverB2Scalar_Flag)
                {
                    case 1:
                        //同类入仓
                        Log4Net.MsgInfo("B2行-入仓操作");
                        Caver.CaverModelNumber_ProgrammeWarehousing(Caver.SearchClassReferenceBRow2(ref CaverB2Eigenvector_Flag)[0], CaverB2SN_Flag.Item1, CaverB2SN_Flag.Item2, ref CaverB2Scalar_Flag);

                        break;

                    case 2:
                        //空仓入仓
                        Caver.CaverModelNumber_ProgrammeWarehousing(Caver.SearchVacancyBRow1()[0], CaverB2SN_Flag.Item1, CaverB2SN_Flag.Item2, ref CaverB2Scalar_Flag);

                        break;

                    default:
                        break;
                }
            }
        }



        #endregion 分类区结点2

        #region 分类区结点3

        public static void ClassifyCaveSGA3()
        {
            //A
            if (CPLCControl.LAD_GetDblCell_(PLC.dCave3_A) == 1 && !SG.CaveSGA3ing)
            {
                SG.CaveSGA3QRCode = "";
                SG.CaveSGA3Action.BeginInvoke(null, null);
                SG.CaveSGA3ing = true;
                Log4Net.MsgInfo("A3结点-扫码");

                ClassifyCaveSGA3QRCodeDisposeAction.BeginInvoke(null, null);
            }

            if (CPLCControl.LAD_GetDblCell_(PLC.dCave3_A) != 1)
            {
                SG.CaveSGA3ing = false;
            }

        }
        public static void ClassifyCaveSGB3()
        {

            //B
            if (CPLCControl.LAD_GetDblCell_(PLC.dCave3_B) == 1 && !SG.CaveSGB3ing)
            {
                SG.CaveSGB3QRCode = "";
                SG.CaveSGB3Action.BeginInvoke(null, null);
                SG.CaveSGB3ing = true;
                Log4Net.MsgInfo("B3结点-扫码");
            }
        }
        private static Action ClassifyCaveSGA3QRCodeDisposeAction = () => { ClassifyCaveSGA3QRCodeDispose(); };
        public static void ClassifyCaveSGA3QRCodeDispose()
        {
            //A
            if (SG.CaveSGA3ing)
            {
                Thread.Sleep(900);
                #region 有效扫码-主线

                if (SG.CaveSGA3QRCode.Length == SG.EffeLength)
                {
                    try
                    {
                        string eig = "";
                        CEigenvector cEigenvector = new CEigenvector(LINE.ZERO, "", KCAndBF.ZERO, Remark.ZERO);
                        MySqlFunction.TrayCellDataList.TrayCellDataList__Eigenvector_SELECT(SG.CaveSGA3QRCode, SG.CaveSGA3QRCode, ref eig);         //查询特征
                        if (eig == "")
                        {
                            Log4Net.MsgInfo("A3结点-特征索引为空");
                            CPLCControl.LAD_SetDblCell(PLC.dCave3_A, 3);
                            SG.CaveSGA3QRCode = "";
                            //SG.CaveSGA3ing = false;
                            return;
                        }
                        Log4Net.MsgInfo("A3结点-特征索引" + eig);

                        string snb = "";
                        MySqlFunction.TrayCellDataList.TrayCellDataList_SN_SELECT(SG.CaveSGA3QRCode, ref snb);          //使用tray中一个sn由数据库索引另外一个sn
                        CaverA3SN_Flag = new Tuple<string, string>(SG.CaveSGA3QRCode, snb);

                        //TODU:首行分配方法
                        CEigenvector.EigenvectorString2C(eig, ref cEigenvector);            //字符串转特征类
                        CaverA3Eigenvector_Flag = new CEigenvector(cEigenvector.LINEi, cEigenvector.PN, cEigenvector.KCAndBF, cEigenvector.Remark);
                        bool flag = false;
                        CaverA3Scalar_Flag = ArrangeA3(ref cEigenvector, ref SG.CaveSGA3QRCode, ref snb, ref flag);
                        Log4Net.MsgInfo("A3行-仓位分配");
                    }
                    catch (Exception)
                    {
                        Log4Net.MsgInfo("A3结点-特征索引为空");
                        CPLCControl.LAD_SetDblCell(PLC.dCave3_A, 3);
                        SG.CaveSGA3QRCode = "";
                        //SG.CaveSGA3ing = false;
                        return;
                    }
                }

                #endregion 有效扫码-主线

                #region 码异常

                else if (SG.CaveSGA3QRCode != "")
                {
                    Log4Net.MsgInfo("A3结点-扫码异常");
                    CPLCControl.LAD_SetDblCell(PLC.dCave3_A, 3);
                    SG.CaveSGA3QRCode = "";
                    //SG.CaveSGA3ing = false;
                    return;
                }

                #endregion 码异常
            }

        }
        public static void ClassifyCaveSGB3QRCodeDispose()
        {
            //B
            if (SG.CaveSGB3ing)
            {
                #region 有效扫码-主线

                if (SG.CaveSGB3QRCode.Length == SG.EffeLength)
                {
                    try
                    {
                        string eig = "";
                        CEigenvector cEigenvector = new CEigenvector(LINE.ZERO, "", KCAndBF.ZERO, Remark.ZERO);
                        MySqlFunction.TrayCellDataList.TrayCellDataList__Eigenvector_SELECT(SG.CaveSGB3QRCode, SG.CaveSGB3QRCode, ref eig);         //查询特征
                        if (eig == "")
                        {
                            Log4Net.MsgInfo("B3结点-特征索引为空");
                            CPLCControl.LAD_SetDblCell_(PLC.dCave3_B, 3);
                            SG.CaveSGB3QRCode = "";
                            SG.CaveSGB3ing = false;
                            return;
                        }
                        Log4Net.MsgInfo("B3结点-特征索引" + eig);

                        string snb = "";
                        MySqlFunction.TrayCellDataList.TrayCellDataList_SN_SELECT(SG.CaveSGB3QRCode, ref snb);          //使用tray中一个sn由数据库索引另外一个sn
                        CaverB3SN_Flag = new Tuple<string, string>(SG.CaveSGB3QRCode, snb);

                        //TODU:首行分配方法
                        CEigenvector.EigenvectorString2C(eig, ref cEigenvector);            //字符串转特征类
                        CaverB3Eigenvector_Flag = new CEigenvector(cEigenvector.LINEi, cEigenvector.PN, cEigenvector.KCAndBF, cEigenvector.Remark);
                        CaverB3Scalar_Flag = ArrangeB3(ref cEigenvector, ref SG.CaveSGB3QRCode, ref snb, ref SG.CaveSGB3ing);
                        Log4Net.MsgInfo("B3行-仓位分配");
                    }
                    catch (Exception)
                    {
                        Log4Net.MsgInfo("B3结点-特征索引为空");
                        CPLCControl.LAD_SetDblCell_(PLC.dCave3_B, 3);
                        SG.CaveSGB3QRCode = "";
                        SG.CaveSGB3ing = false;
                        return;
                    }
                }

                #endregion 有效扫码-主线

                #region 码异常

                else if (SG.CaveSGB3QRCode != "")
                {
                    Log4Net.MsgInfo("B3结点-扫码异常");
                    CPLCControl.LAD_SetDblCell_(PLC.dCave3_B, 3);
                    SG.CaveSGB3QRCode = "";
                    SG.CaveSGB3ing = false;
                    return;
                }

                #endregion 码异常
            }
        }

        public static void ClassifyCaveSG3PutStorage()
        {
            if (CPLCControl.LAD_GetDblCell_(PLC.dCave3_A) == 4)
            {
                Log4Net.MsgInfo("A3结点-顶升完成");
                switch (CaverA3Scalar_Flag)
                {
                    case 1:
                        //同类入仓
                        Log4Net.MsgInfo("A3行-入仓操作");
                        Caver.CaverModelNumber_ProgrammeWarehousing(Caver.SearchClassReferenceARow3(ref CaverA3Eigenvector_Flag)[0], CaverA3SN_Flag.Item1, CaverA3SN_Flag.Item2,ref CaverA3Scalar_Flag);

                        break;

                    case 2:
                        //空仓入仓
                        Caver.CaverModelNumber_ProgrammeWarehousing(Caver.SearchVacancyARow3()[0], CaverA3SN_Flag.Item1, CaverA3SN_Flag.Item2, ref CaverA3Scalar_Flag);

                        break;

                    default:
                        break;
                }
            }

            if (CPLCControl.LAD_GetDblCell_(PLC.dCave3_B) == 4)
            {
                Log4Net.MsgInfo("B3结点-顶升完成");
                switch (CaverB3Scalar_Flag)
                {
                    case 1:
                        //同类入仓
                        Log4Net.MsgInfo("B3行-入仓操作");
                        Caver.CaverModelNumber_ProgrammeWarehousing(Caver.SearchClassReferenceBRow3(ref CaverB3Eigenvector_Flag)[0], CaverB3SN_Flag.Item1, CaverB3SN_Flag.Item2, ref CaverB3Scalar_Flag);
                        break;

                    case 2:
                        //空仓入仓
                        Caver.CaverModelNumber_ProgrammeWarehousing(Caver.SearchVacancyBRow3()[0], CaverB3SN_Flag.Item1, CaverB3SN_Flag.Item2, ref CaverB3Scalar_Flag);
                        break;

                    default:
                        break;
                }
            }
        }


        #endregion 分类区结点3

        #region 分类区方法

        #region 分类区存在同类

        //************************************************
        //类似"递归"的方式 第一第二排模式一致，第三排不存在放行考虑等待模组空闲放置空位和同类位
        //************************************************
        /// <summary>
        /// 第一排
        /// </summary>
        /// <param name="cEigenvector"></param>
        /// <param name="sna"></param>
        /// <param name="snb"></param>
        /// <returns>0:放行；1:同类入仓；2:空仓入仓</returns>
        public static byte ArrangeA1(ref CEigenvector cEigenvector, ref string sna, ref string snb, ref bool flag)
        {
            #region 优先考虑后排空闲
            if (CPLCControl.LAD_CheckCell(PLC.mHandBusy_A2) == 1 && !SG.CaveSGA2ing && !SensorBit(1))
            {
                Log4Net.MsgInfo("A1结点-后排有空闲");
                if (Caver.SearchClassReferenceARow2(ref cEigenvector).Count != 0)
                {
                    Log4Net.MsgInfo("A1结点-后排有同类-优先" + cEigenvector.StringEigenvector);
                    CPLCControl.LAD_SetDblCell(PLC.dCave1_A, 3);
                    Log4Net.MsgInfo("A1结点-放行");
                    sna = ""; snb = "";
                    flag = false;
                    return 0;   //返回
                }
                else if (Caver.SearchVacancyARow2().Count != 0)
                {
                    Log4Net.MsgInfo("A1结点-后排有空位-优先");

                    #region 实例增加
                    int num = Caver.SearchVacancyARow2()[0];
                    Log4Net.MsgInfo("A2行-新类注册空仓" + num);
                    Caver.CaverModelNumber_Eigenvector(num, ref cEigenvector);
                    CaverBuffData.WriteCaverEigenvector(num, ref cEigenvector);
                    #endregion 实例增加

                    Log4Net.MsgInfo("A区-同类仓增加：" + cEigenvector.StringEigenvector);
                    CPLCControl.LAD_SetDblCell(PLC.dCave1_A, 3);
                    Log4Net.MsgInfo("A1结点-放行");
                    sna = ""; snb = "";
                    flag = false;
                    return 0;   //返回
                }

            }
            #endregion
            


            if (Caver.SearchClassReferenceARow1(ref cEigenvector).Count != 0)
            {
                Log4Net.MsgInfo("A1行-存在同类：" + cEigenvector.StringEigenvector);
                if (CPLCControl.LAD_CheckCell(PLC.mHandBusy_A1) == 1)
                {
                    Log4Net.MsgInfo("A1模组-空闲");
                    //CPLCControl.LAD_SetDblCell(PLC.dCave1_A, 2);

                    //
                    int nunmber = Caver.SearchClassReferenceARow1(ref cEigenvector)[0];
                    Caver.CaverModelNumber_ProgrammeWarehousing_(nunmber, sna, snb);
                    CPLCControl.LAD_SetDblCell(PLC.dCave1_A,(short)( 20 + nunmber%10));
                    //

                    Log4Net.MsgInfo("A1结点-开启顶升");
                    Log4Net.MsgInfo("A1行-同类入仓");
                    sna = ""; snb = "";
                    flag = false;
                    return 1;
                }
                else
                {
                    if (Caver.SearchClassReferenceARow2(ref cEigenvector).Count != 0 || Caver.SearchClassReferenceARow3(ref cEigenvector).Count != 0)
                    {
                        Log4Net.MsgInfo("A1模组-忙，A2A3行存在同类");
                        CPLCControl.LAD_SetDblCell(PLC.dCave1_A, 3);
                        Log4Net.MsgInfo("A1结点-放行");
                        sna = ""; snb = "";
                        flag = false;
                        return 0;   //返回
                    }
                    else
                    {
                        //后排无同类
                        if (Caver.SearchVacancyARow2().Count != 0 || Caver.SearchVacancyARow3().Count != 0)
                        {
                            Log4Net.MsgInfo("A1模组-忙，A2A3都不存在同类，后排存在空位");
                            //TODU:考虑实例激增的方法

                            #region 实例增加

                            if (Caver.SearchVacancyARow2().Count != 0)
                            {
                                int num = Caver.SearchVacancyARow2()[0];
                                Log4Net.MsgInfo("A2行-新类注册空仓" + num);
                                Caver.CaverModelNumber_Eigenvector(num, ref cEigenvector);
                                CaverBuffData.WriteCaverEigenvector(num, ref cEigenvector);
                            }
                            else if (Caver.SearchVacancyARow3().Count != 0)
                            {
                                int num = Caver.SearchVacancyARow3()[0];
                                Log4Net.MsgInfo("A3行-新类注册空仓" + num);
                                Caver.CaverModelNumber_Eigenvector(num, ref cEigenvector);
                                CaverBuffData.WriteCaverEigenvector(num, ref cEigenvector);
                            }

                            #endregion 实例增加

                            Log4Net.MsgInfo("A区-同类仓增加：" + cEigenvector.StringEigenvector);
                            CPLCControl.LAD_SetDblCell(PLC.dCave1_A, 3);
                            Log4Net.MsgInfo("A1结点-放行");
                            sna = ""; snb = "";
                            flag = false;
                            return 0;   //返回
                        }
                        else
                        {
                            if (CPLCControl.LAD_CheckCell(PLC.mHandBusy_A1) == 1)
                            {
                                Log4Net.MsgInfo("A1模组忙-A2A3都不存在同类，后排无空位");
                                Log4Net.MsgInfo("A1行-等待模组空闲");
                                //首行模组空闲
                                //CPLCControl.LAD_SetDblCell(PLC.dCave1_A, 2);        //结点准备
                                //
                                int nunmber = Caver.SearchClassReferenceARow1(ref cEigenvector)[0];
                                Caver.CaverModelNumber_ProgrammeWarehousing_(nunmber, sna, snb);
                                CPLCControl.LAD_SetDblCell(PLC.dCave1_A, (short)(20 + nunmber % 10));
                                //
                                Log4Net.MsgInfo("A1结点-开启顶升");
                                sna = ""; snb = "";
                                flag = false;
                                return 1;
                            }
                            return 1;
                        }
                    }
                }
            }
            //TODU:逆向判断-后排同类但模组忙-小时段内单一集中类型进入
            else if (Caver.SearchVacancyARow1().Count != 0)
            {
                Log4Net.MsgInfo("A1行-不存在同类，A1存在空位");
                if (CPLCControl.LAD_CheckCell(PLC.mHandBusy_A2) != 1 || SG.CaveSGA2ing||SensorBit(1))
                {
                    Log4Net.MsgInfo("A2行-忙" + "A2行-存在任务");
                    #region 实例增加

                    if (Caver.SearchVacancyARow1().Count != 0)
                    {
                        int num = Caver.SearchVacancyARow1()[0];
                        Log4Net.MsgInfo("A1行-新类注册空仓" + num);
                        Caver.CaverModelNumber_Eigenvector(num, ref cEigenvector);
                        CaverBuffData.WriteCaverEigenvector(num, ref cEigenvector);
                    }

                    #endregion 实例增加
                    //CPLCControl.LAD_SetDblCell(PLC.dCave1_A, 2);
                    //
                    int nunmber = Caver.SearchClassReferenceARow1(ref cEigenvector)[0];
                    Caver.CaverModelNumber_ProgrammeWarehousing_(nunmber, sna, snb);
                    CPLCControl.LAD_SetDblCell(PLC.dCave1_A, (short)(20 + nunmber % 10));
                    //
                    Log4Net.MsgInfo("A1结点-开启顶升");
                    Log4Net.MsgInfo("A1行-同类入仓");
                    sna = ""; snb = "";
                    flag = false;
                    return 1;
                }
                else
                {
                    #region 正向判断-"方法段"
                    if (Caver.SearchClassReferenceARow2(ref cEigenvector).Count != 0 || Caver.SearchClassReferenceARow3(ref cEigenvector).Count != 0)
                    {
                        Log4Net.MsgInfo("A1行-不存在同类，A2A3存在同类");
                        CPLCControl.LAD_SetDblCell(PLC.dCave1_A, 3);
                        Log4Net.MsgInfo("A1结点-放行");
                        sna = ""; snb = "";
                        flag = false;
                        return 0;   //返回
                    }
                    else
                    {
                        Log4Net.MsgInfo("A区-不存在同类");
                        return NewArrangeA(ref cEigenvector, ref sna, ref snb, ref flag);
                    }
                    #endregion

                }

            }
            #region 正向判断-"方法段"
            else if (Caver.SearchClassReferenceARow2(ref cEigenvector).Count != 0 || Caver.SearchClassReferenceARow3(ref cEigenvector).Count != 0)
            {
                Log4Net.MsgInfo("A1行-不存在同类，A2A3存在同类");
                CPLCControl.LAD_SetDblCell(PLC.dCave1_A, 3);
                Log4Net.MsgInfo("A1结点-放行");
                sna = ""; snb = "";
                flag = false;
                return 0;   //返回
            }
            else
            {
                Log4Net.MsgInfo("A区-不存在同类");
                return NewArrangeA(ref cEigenvector, ref sna, ref snb, ref flag);
            }
            #endregion
        }

        public static byte ArrangeB1(ref CEigenvector cEigenvector, ref string sna, ref string snb, ref bool flag)
        {

            #region 优先考虑后排空闲
            if (CPLCControl.LAD_CheckCell_(PLC.mHandBusy_B2) == 1 && !SG.CaveSGB2ing && !SensorBit(1))
            {
                Log4Net.MsgInfo("B1结点-后排有空闲");
                if (Caver.SearchClassReferenceBRow2(ref cEigenvector).Count != 0)
                {
                    Log4Net.MsgInfo("B1结点-后排有同类-优先" + cEigenvector.StringEigenvector);
                    CPLCControl.LAD_SetDblCell_(PLC.dCave1_B, 3);
                    Log4Net.MsgInfo("B1结点-放行");
                    sna = ""; snb = "";
                    flag = false;
                    return 0;   //返回
                }
                else if (Caver.SearchVacancyBRow2().Count != 0)
                {
                    Log4Net.MsgInfo("B1结点-后排有空位-优先");

                    #region 实例增加
                    int num = Caver.SearchVacancyBRow2()[0];
                    Log4Net.MsgInfo("B2行-新类注册空仓" + num);
                    Caver.CaverModelNumber_Eigenvector(num, ref cEigenvector);
                    CaverBuffData.WriteCaverEigenvector(num, ref cEigenvector);
                    #endregion 实例增加

                    Log4Net.MsgInfo("B区-同类仓增加：" + cEigenvector.StringEigenvector);
                    CPLCControl.LAD_SetDblCell_(PLC.dCave1_B, 3);
                    Log4Net.MsgInfo("B1结点-放行");
                    sna = ""; snb = "";
                    flag = false;
                    return 0;   //返回
                }

            }
            #endregion



            if (Caver.SearchClassReferenceBRow1(ref cEigenvector).Count != 0)
            {
                Log4Net.MsgInfo("B1行-存在同类：" + cEigenvector.StringEigenvector);
                if (CPLCControl.LAD_CheckCell_(PLC.mHandBusy_B1) == 1)
                {
                    Log4Net.MsgInfo("B1模组-空闲");
                    //CPLCControl.LAD_SetDblCell_(PLC.dCave1_B, 2);
                    #region 转值
                    int nunmber = Caver.SearchClassReferenceBRow1(ref cEigenvector)[0];
                    Caver.CaverModelNumber_ProgrammeWarehousing_(nunmber, sna, snb);
                    CPLCControl.LAD_SetDblCell_(PLC.dCave1_B, (short)(20 + nunmber % 10));
                    #endregion
                    Log4Net.MsgInfo("B1结点-开启顶升");
                    Log4Net.MsgInfo("B1行-同类入仓");
                    sna = ""; snb = "";
                    flag = false;
                    return 1;
                }
                else
                {
                    if (Caver.SearchClassReferenceBRow2(ref cEigenvector).Count != 0 || Caver.SearchClassReferenceBRow3(ref cEigenvector).Count != 0)
                    {
                        Log4Net.MsgInfo("B1模组-忙，B2B3行存在同类");
                        CPLCControl.LAD_SetDblCell_(PLC.dCave1_B, 3);
                        Log4Net.MsgInfo("B1结点-放行");
                        sna = ""; snb = "";
                        flag = false;
                        return 0;   //返回
                    }
                    else
                    {
                        //后排无同类
                        if (Caver.SearchVacancyBRow2().Count != 0 || Caver.SearchVacancyBRow3().Count != 0)
                        {
                            Log4Net.MsgInfo("B1模组-忙，B2B3都不存在同类，后排存在空位");
                            //TODU:考虑实例激增的方法

                            #region 实例增加

                            if (Caver.SearchVacancyBRow2().Count != 0)
                            {
                                int num = Caver.SearchVacancyBRow2()[0];
                                Log4Net.MsgInfo("B2行-新类注册空仓" + num);
                                Caver.CaverModelNumber_Eigenvector(num, ref cEigenvector);
                                CaverBuffData.WriteCaverEigenvector(num, ref cEigenvector);
                            }
                            else if (Caver.SearchVacancyBRow3().Count != 0)
                            {
                                int num = Caver.SearchVacancyBRow3()[0];
                                Log4Net.MsgInfo("B3行-新类注册空仓" + num);
                                Caver.CaverModelNumber_Eigenvector(num, ref cEigenvector);
                                CaverBuffData.WriteCaverEigenvector(num, ref cEigenvector);
                            }

                            #endregion 实例增加

                            Log4Net.MsgInfo("B区-同类仓增加：" + cEigenvector.StringEigenvector);
                            CPLCControl.LAD_SetDblCell_(PLC.dCave1_B, 3);
                            Log4Net.MsgInfo("B1结点-放行");
                            sna = ""; snb = "";
                            flag = false;
                            return 0;   //返回
                        }
                        else
                        {
                            if (CPLCControl.LAD_CheckCell_(PLC.mHandBusy_B1) == 1)
                            {
                                Log4Net.MsgInfo("B1模组忙-B2B3都不存在同类，后排无空位");
                                Log4Net.MsgInfo("B1行-等待模组空闲");
                                //首行模组空闲
                                //CPLCControl.LAD_SetDblCell_(PLC.dCave1_B, 2);        //结点准备
                                #region 转值
                                int nunmber = Caver.SearchClassReferenceBRow1(ref cEigenvector)[0];
                                Caver.CaverModelNumber_ProgrammeWarehousing_(nunmber, sna, snb);
                                CPLCControl.LAD_SetDblCell_(PLC.dCave1_B, (short)(20 + nunmber % 10));
                                #endregion
                                Log4Net.MsgInfo("B1结点-开启顶升");
                                sna = ""; snb = "";
                                flag = false;
                                return 1;
                            }
                            return 1;
                        }
                    }
                }
            }
            //TODU:逆向判断-后排同类但模组忙-小时段内单一集中类型进入
            else if (Caver.SearchVacancyBRow1().Count != 0)
            {
                Log4Net.MsgInfo("B1行-不存在同类，B1存在空位");
                if (CPLCControl.LAD_CheckCell_(PLC.mHandBusy_B2) != 1 || SG.CaveSGB2ing || SensorBit(9))
                {
                    Log4Net.MsgInfo("B2行-忙" + "B2行-存在任务");
                    #region 实例增加

                    if (Caver.SearchVacancyBRow1().Count != 0)
                    {
                        int num = Caver.SearchVacancyBRow1()[0];
                        Log4Net.MsgInfo("B1行-新类注册空仓" + num);
                        Caver.CaverModelNumber_Eigenvector(num, ref cEigenvector);
                        CaverBuffData.WriteCaverEigenvector(num, ref cEigenvector);
                    }

                    #endregion 实例增加
                    //CPLCControl.LAD_SetDblCell_(PLC.dCave1_B, 2);
                    #region 转值
                    int nunmber = Caver.SearchClassReferenceBRow1(ref cEigenvector)[0];
                    Caver.CaverModelNumber_ProgrammeWarehousing_(nunmber, sna, snb);
                    CPLCControl.LAD_SetDblCell_(PLC.dCave1_B, (short)(20 + nunmber % 10));
                    #endregion
                    Log4Net.MsgInfo("B1结点-开启顶升");
                    Log4Net.MsgInfo("B1行-同类入仓");
                    sna = ""; snb = "";
                    flag = false;
                    return 1;
                }
                else
                {
                    #region 正向判断-"方法段"
                    if (Caver.SearchClassReferenceBRow2(ref cEigenvector).Count != 0 || Caver.SearchClassReferenceBRow3(ref cEigenvector).Count != 0)
                    {
                        Log4Net.MsgInfo("B1行-不存在同类，B2B3存在同类");
                        CPLCControl.LAD_SetDblCell_(PLC.dCave1_B, 3);
                        Log4Net.MsgInfo("B1结点-放行");
                        sna = ""; snb = "";
                        flag = false;
                        return 0;   //返回
                    }
                    else
                    {
                        Log4Net.MsgInfo("B区-不存在同类");
                        return NewArrangeB(ref cEigenvector, ref sna, ref snb, ref flag);
                    }
                    #endregion

                }

            }
            #region 正向判断-"方法段"
            else if (Caver.SearchClassReferenceBRow2(ref cEigenvector).Count != 0 || Caver.SearchClassReferenceBRow3(ref cEigenvector).Count != 0)
            {
                Log4Net.MsgInfo("B1行-不存在同类，B2B3存在同类");
                CPLCControl.LAD_SetDblCell_(PLC.dCave1_B, 3);
                Log4Net.MsgInfo("B1结点-放行");
                sna = ""; snb = "";
                flag = false;
                return 0;   //返回
            }
            else
            {
                Log4Net.MsgInfo("B区-不存在同类");
                return NewArrangeB(ref cEigenvector, ref sna, ref snb, ref flag);
            }
            #endregion




            //if (Caver.SearchClassReferenceBRow1(ref cEigenvector).Count != 0)
            //{
            //    Log4Net.MsgInfo("B1行-存在同类：" + cEigenvector.StringEigenvector);
            //    if (CPLCControl.LAD_CheckCell_(PLC.mHandBusy_B1) == 1)
            //    {
            //        Log4Net.MsgInfo("B1模组-空闲");
            //        CPLCControl.LAD_SetDblCell_(PLC.dCave1_B, 2);
            //        Log4Net.MsgInfo("B1结点-开启顶升");
            //        Log4Net.MsgInfo("B1行-同类入仓");
            //        sna = ""; snb = "";
            //        flag = false;
            //        return 1;
            //    }
            //    else
            //    {
            //        if (Caver.SearchClassReferenceBRow2(ref cEigenvector).Count != 0 || Caver.SearchClassReferenceBRow3(ref cEigenvector).Count != 0)
            //        {
            //            Log4Net.MsgInfo("B1模组-忙，B2B3行存在同类");
            //            CPLCControl.LAD_SetDblCell_(PLC.dCave1_B, 3);
            //            Log4Net.MsgInfo("B1结点-放行");
            //            sna = ""; snb = "";
            //            flag = false;
            //            return 0;   //返回
            //        }
            //        else
            //        {
            //            //后排无同类
            //            if (Caver.SearchVacancyBRow2().Count != 0 || Caver.SearchVacancyBRow3().Count != 0)
            //            {
            //                Log4Net.MsgInfo("B1模组-忙，B2B3都不存在同类，后排存在空位");
            //                //TODU:考虑实例激增的方法

            //                #region 实例增加

            //                if (Caver.SearchVacancyBRow2().Count != 0)
            //                {
            //                    int num = Caver.SearchVacancyBRow2()[0];
            //                    Log4Net.MsgInfo("B2行-新类注册空仓" + num);
            //                    Caver.CaverModelNumber_Eigenvector(num, ref cEigenvector);
            //                    CaverBuffData.WriteCaverEigenvector(num, ref cEigenvector);
            //                }
            //                else if (Caver.SearchVacancyBRow3().Count != 0)
            //                {
            //                    int num = Caver.SearchVacancyBRow3()[0];
            //                    Log4Net.MsgInfo("B3行-新类注册空仓" + num);
            //                    Caver.CaverModelNumber_Eigenvector(num, ref cEigenvector);
            //                    CaverBuffData.WriteCaverEigenvector(num, ref cEigenvector);
            //                }

            //                #endregion 实例增加

            //                Log4Net.MsgInfo("B区-同类仓增加：" + cEigenvector.StringEigenvector);
            //                CPLCControl.LAD_SetDblCell_(PLC.dCave1_B, 3);
            //                Log4Net.MsgInfo("B1结点-放行");
            //                sna = ""; snb = "";
            //                flag = false;
            //                return 0;   //返回
            //            }
            //            else
            //            {
            //                if (CPLCControl.LAD_CheckCell_(PLC.mHandBusy_B1) == 1)
            //                {
            //                    Log4Net.MsgInfo("B1模组忙-B2B3都不存在同类，后排无空位");
            //                    Log4Net.MsgInfo("B1行-等待模组空闲");
            //                    //首行模组空闲
            //                    CPLCControl.LAD_SetDblCell_(PLC.dCave1_B, 2);        //结点准备
            //                    Log4Net.MsgInfo("B1结点-开启顶升");
            //                    sna = ""; snb = "";
            //                    flag = false;
            //                    return 1;
            //                }
            //                return 1;
            //            }
            //        }
            //    }
            //}
            //else if (Caver.SearchClassReferenceBRow2(ref cEigenvector).Count != 0 || Caver.SearchClassReferenceBRow3(ref cEigenvector).Count != 0)
            //{
            //    Log4Net.MsgInfo("B1行-不存在同类，B2B3存在同类");
            //    CPLCControl.LAD_SetDblCell_(PLC.dCave1_B, 3);
            //    Log4Net.MsgInfo("B1结点-放行");
            //    sna = ""; snb = "";
            //    flag = false;
            //    return 0;   //返回
            //}
            //else
            //{
            //    Log4Net.MsgInfo("B区-不存在同类");
            //    return NewArrangeB(ref cEigenvector, ref sna, ref snb, ref flag);
            //}
        }

        /// <summary>
        /// 第二排
        /// </summary>
        /// <param name="cEigenvector"></param>
        /// <param name="sna"></param>
        /// <param name="snb"></param>
        public static byte ArrangeA2(ref CEigenvector cEigenvector, ref string sna, ref string snb, ref bool flag)
        {
            #region 后排空闲优先
            if (CPLCControl.LAD_CheckCell(PLC.mHandBusy_A3) == 1 && !SG.CaveSGA3ing && !SensorBit(2))
            {
                Log4Net.MsgInfo("A2结点-后排有空闲");
                if (Caver.SearchClassReferenceARow3(ref cEigenvector).Count != 0)
                {
                    Log4Net.MsgInfo("A2结点-后排有同类-优先" + cEigenvector.StringEigenvector);
                    CPLCControl.LAD_SetDblCell(PLC.dCave2_A, 3);
                    Log4Net.MsgInfo("A2结点-放行");
                    sna = ""; snb = "";
                    flag = false;
                    return 0;   //返回
                }
                else if (Caver.SearchVacancyARow3().Count != 0)
                {
                    Log4Net.MsgInfo("A2结点-后排有空位-优先");

                    #region 实例增加
                    int num = Caver.SearchVacancyARow3()[0];
                    Log4Net.MsgInfo("A3行-新类注册空仓" + num);
                    Caver.CaverModelNumber_Eigenvector(num, ref cEigenvector);
                    CaverBuffData.WriteCaverEigenvector(num, ref cEigenvector);
                    #endregion 实例增加

                    Log4Net.MsgInfo("A区-同类仓增加：" + cEigenvector.StringEigenvector);
                    CPLCControl.LAD_SetDblCell(PLC.dCave2_A, 3);
                    Log4Net.MsgInfo("A2结点-放行");
                    sna = ""; snb = "";
                    flag = false;
                    return 0;   //返回
                }
            }
            #endregion




            //A区第二行存在同类
            if (Caver.SearchClassReferenceARow2(ref cEigenvector).Count != 0)
            {
                Log4Net.MsgInfo("A2行-存在同类：" + cEigenvector.StringEigenvector);
                //二行就存在同类
                if (CPLCControl.LAD_CheckCell(PLC.mHandBusy_A2) == 1)
                {
                    Log4Net.MsgInfo("A2模组-空闲");
                    //CPLCControl.LAD_SetDblCell(PLC.dCave2_A, 2);        //结点准备
                    #region 转值
                    int nunmber = Caver.SearchClassReferenceARow2(ref cEigenvector)[0];
                    Caver.CaverModelNumber_ProgrammeWarehousing_(nunmber, sna, snb);
                    CPLCControl.LAD_SetDblCell(PLC.dCave2_A, (short)(20 + nunmber % 10));
                    #endregion
                    Log4Net.MsgInfo("A2结点-开启顶升");
                    Log4Net.MsgInfo("A2行-同类入仓");
                    sna = ""; snb = "";
                    flag = false;
                    return 1;
                }
                else
                {
                    if (Caver.SearchClassReferenceARow3(ref cEigenvector).Count != 0)
                    {
                        Log4Net.MsgInfo("A2模组-忙，A3行存在同类");
                        CPLCControl.LAD_SetDblCell(PLC.dCave2_A, 3);
                        Log4Net.MsgInfo("A2结点-放行");
                        sna = ""; snb = "";
                        flag = false;
                        return 0;   //返回
                    }
                    else
                    {
                        //后排无同类
                        if (Caver.SearchVacancyARow3().Count != 0)
                        {
                            Log4Net.MsgInfo("A2模组-忙，A3都不存在同类，后排存在空位");
                            //TODU:考虑实例激增的方法

                            #region 实例增加

                            int num = Caver.SearchVacancyARow3()[0];
                            Log4Net.MsgInfo("A3行-新类注册空仓" + num);
                            Caver.CaverModelNumber_Eigenvector(num, ref cEigenvector);
                            CaverBuffData.WriteCaverEigenvector(num, ref cEigenvector);

                            #endregion 实例增加

                            Log4Net.MsgInfo("A区-同类仓增加：" + cEigenvector.StringEigenvector);
                            CPLCControl.LAD_SetDblCell(PLC.dCave2_A, 3);
                            Log4Net.MsgInfo("A2结点-放行");
                            sna = ""; snb = "";
                            flag = false;
                            return 0;   //返回
                        }
                        else
                        {
                            if (CPLCControl.LAD_CheckCell(PLC.mHandBusy_A2) == 1)
                            {
                                Log4Net.MsgInfo("A2模组忙-A3都不存在同类，后排无空位");
                                Log4Net.MsgInfo("A2行-等待模组空闲");
                                //二行模组空闲
                                //CPLCControl.LAD_SetDblCell(PLC.dCave2_A, 2);        //结点准备
                                #region 转值
                                int nunmber = Caver.SearchClassReferenceARow2(ref cEigenvector)[0];
                                Caver.CaverModelNumber_ProgrammeWarehousing_(nunmber, sna, snb);
                                CPLCControl.LAD_SetDblCell(PLC.dCave2_A, (short)(20 + nunmber % 10));
                                #endregion
                                Log4Net.MsgInfo("A2结点-开启顶升");
                                sna = ""; snb = "";
                                flag = false;
                                return 1;
                            }
                            return 1;
                        }
                    }
                }
            }
            //TODU:逆向判断-后排同类但模组忙-小时段内单一集中类型进入
            else if (Caver.SearchVacancyARow2().Count != 0)
            {
                Log4Net.MsgInfo("A2行-不存在同类，A2存在空位");
                if (CPLCControl.LAD_CheckCell(PLC.mHandBusy_A3) != 1 ||SG.CaveSGA3ing|| SensorBit(2))
                {
                    Log4Net.MsgInfo("A3行-忙" + "A3行-存在任务");
                    #region 实例增加

                    if (Caver.SearchVacancyARow2().Count != 0)
                    {
                        int num = Caver.SearchVacancyARow2()[0];
                        Log4Net.MsgInfo("A1行-新类注册空仓" + num);
                        Caver.CaverModelNumber_Eigenvector(num, ref cEigenvector);
                        CaverBuffData.WriteCaverEigenvector(num, ref cEigenvector);
                    }

                    #endregion 实例增加
                    //CPLCControl.LAD_SetDblCell(PLC.dCave2_A, 2);
                    #region 转值
                    int nunmber = Caver.SearchClassReferenceARow2(ref cEigenvector)[0];
                    Caver.CaverModelNumber_ProgrammeWarehousing_(nunmber, sna, snb);
                    CPLCControl.LAD_SetDblCell(PLC.dCave2_A, (short)(20 + nunmber % 10));
                    #endregion
                    Log4Net.MsgInfo("A2结点-开启顶升");
                    Log4Net.MsgInfo("A2行-同类入仓");
                    sna = ""; snb = "";
                    flag = false;
                    return 1;
                }
                else
                {
                    #region 正向判断-“方法段”
                    if (Caver.SearchClassReferenceARow3(ref cEigenvector).Count != 0)
                    {
                        Log4Net.MsgInfo("A2行-不存在同类，A3存在同类");
                        CPLCControl.LAD_SetDblCell(PLC.dCave2_A, 3);
                        Log4Net.MsgInfo("A2结点-放行");
                        sna = ""; snb = "";
                        flag = false;
                        return 0;   //返回
                    }
                    else
                    {
                        Log4Net.MsgInfo("A2行-不存在同类，A3不存在同类");
                        if (Caver.SearchVacancyARow2().Count != 0)
                        {
                            Log4Net.MsgInfo("A2行-存在空位");
                            //TODU:考虑实例激增的方法

                            #region 实例增加

                            int num = Caver.SearchVacancyARow2()[0];
                            Log4Net.MsgInfo("A2行-新类注册空仓" + num);
                            Caver.CaverModelNumber_Eigenvector(num, ref cEigenvector);
                            CaverBuffData.WriteCaverEigenvector(num, ref cEigenvector);

                            #endregion 实例增加

                            Log4Net.MsgInfo("A区-同类仓增加：" + cEigenvector.StringEigenvector);
                            //CPLCControl.LAD_SetDblCell(PLC.dCave2_A, 2);
                            #region 转值
                            int nunmber = Caver.SearchClassReferenceARow2(ref cEigenvector)[0];
                            Caver.CaverModelNumber_ProgrammeWarehousing_(nunmber, sna, snb);
                            CPLCControl.LAD_SetDblCell(PLC.dCave2_A, (short)(20 + nunmber % 10));
                            #endregion
                            Log4Net.MsgInfo("A2结点-顶升");
                            sna = ""; snb = "";
                            flag = false;
                            return 1;
                        }
                        else if (Caver.SearchVacancyARow3().Count != 0)
                        {
                            Log4Net.MsgInfo("A3行-存在空位");
                            //TODU:考虑实例激增的方法

                            #region 实例增加

                            int num = Caver.SearchVacancyARow3()[0];
                            Log4Net.MsgInfo("A3行-新类注册空仓" + num);
                            Caver.CaverModelNumber_Eigenvector(num, ref cEigenvector);
                            CaverBuffData.WriteCaverEigenvector(num, ref cEigenvector);

                            #endregion 实例增加

                            Log4Net.MsgInfo("A区-同类仓增加：" + cEigenvector.StringEigenvector);
                            CPLCControl.LAD_SetDblCell(PLC.dCave2_A, 3);
                            Log4Net.MsgInfo("A2结点-放行");
                            sna = ""; snb = "";
                            flag = false;
                            return 0;   //返回
                        }
                        else
                        {
                            Log4Net.MsgInfo("A2行-不存在同类，A3不存在同类-A2A3无空位");
                            CPLCControl.LAD_SetDblCell(PLC.dCave2_A, 3);
                            Log4Net.MsgInfo("A2结点-放行");
                            sna = ""; snb = "";
                            flag = false;
                            return 0;   //返回
                        }
                    }
                    #endregion

                }
            }
            #region 正向判断-“方法段”
            if (Caver.SearchClassReferenceARow3(ref cEigenvector).Count != 0)
            {
                Log4Net.MsgInfo("A2行-不存在同类，A3存在同类");
                CPLCControl.LAD_SetDblCell(PLC.dCave2_A, 3);
                Log4Net.MsgInfo("A2结点-放行");
                sna = ""; snb = "";
                flag = false;
                return 0;   //返回
            }
            else
            {
                Log4Net.MsgInfo("A2行-不存在同类，A3不存在同类");
                if (Caver.SearchVacancyARow2().Count != 0)
                {
                    Log4Net.MsgInfo("A2行-存在空位");
                    //TODU:考虑实例激增的方法

                    #region 实例增加

                    int num = Caver.SearchVacancyARow2()[0];
                    Log4Net.MsgInfo("A2行-新类注册空仓" + num);
                    Caver.CaverModelNumber_Eigenvector(num, ref cEigenvector);
                    CaverBuffData.WriteCaverEigenvector(num, ref cEigenvector);

                    #endregion 实例增加

                    Log4Net.MsgInfo("A区-同类仓增加：" + cEigenvector.StringEigenvector);
                    //CPLCControl.LAD_SetDblCell(PLC.dCave2_A, 2);
                    #region 转值
                    int nunmber = Caver.SearchClassReferenceARow2(ref cEigenvector)[0];
                    Caver.CaverModelNumber_ProgrammeWarehousing_(nunmber, sna, snb);
                    CPLCControl.LAD_SetDblCell(PLC.dCave2_A, (short)(20 + nunmber % 10));
                    #endregion
                    Log4Net.MsgInfo("A2结点-顶升");
                    sna = ""; snb = "";
                    flag = false;
                    return 1;
                }
                else if (Caver.SearchVacancyARow3().Count != 0)
                {
                    Log4Net.MsgInfo("A3行-存在空位");
                    //TODU:考虑实例激增的方法

                    #region 实例增加

                    int num = Caver.SearchVacancyARow3()[0];
                    Log4Net.MsgInfo("A3行-新类注册空仓" + num);
                    Caver.CaverModelNumber_Eigenvector(num, ref cEigenvector);
                    CaverBuffData.WriteCaverEigenvector(num, ref cEigenvector);

                    #endregion 实例增加

                    Log4Net.MsgInfo("A区-同类仓增加：" + cEigenvector.StringEigenvector);
                    CPLCControl.LAD_SetDblCell(PLC.dCave2_A, 3);
                    Log4Net.MsgInfo("A2结点-放行");
                    sna = ""; snb = "";
                    flag = false;
                    return 0;   //返回
                }
                else
                {
                    Log4Net.MsgInfo("A2行-不存在同类，A3不存在同类-A2A3无空位");
                    CPLCControl.LAD_SetDblCell(PLC.dCave2_A, 3);
                    Log4Net.MsgInfo("A2结点-放行");
                    sna = ""; snb = "";
                    flag = false;
                    return 0;   //返回
                }
            }
            #endregion
        }

        public static byte ArrangeB2(ref CEigenvector cEigenvector, ref string sna, ref string snb, ref bool flag)
        {
            #region 后排空闲优先
            if (CPLCControl.LAD_CheckCell_(PLC.mHandBusy_B3) == 1 && !SG.CaveSGB3ing && !SensorBit(10))
            {
                Log4Net.MsgInfo("B2结点-后排有空闲");
                if (Caver.SearchClassReferenceBRow3(ref cEigenvector).Count != 0)
                {
                    Log4Net.MsgInfo("B2结点-后排有同类-优先" + cEigenvector.StringEigenvector);
                    CPLCControl.LAD_SetDblCell_(PLC.dCave2_B, 3);
                    Log4Net.MsgInfo("B2结点-放行");
                    sna = ""; snb = "";
                    flag = false;
                    return 0;   //返回
                }
                else if (Caver.SearchVacancyBRow3().Count != 0)
                {
                    Log4Net.MsgInfo("B2结点-后排有空位-优先");

                    #region 实例增加
                    int num = Caver.SearchVacancyBRow3()[0];
                    Log4Net.MsgInfo("B3行-新类注册空仓" + num);
                    Caver.CaverModelNumber_Eigenvector(num, ref cEigenvector);
                    CaverBuffData.WriteCaverEigenvector(num, ref cEigenvector);
                    #endregion 实例增加

                    Log4Net.MsgInfo("B区-同类仓增加：" + cEigenvector.StringEigenvector);
                    CPLCControl.LAD_SetDblCell_(PLC.dCave2_B, 3);
                    Log4Net.MsgInfo("B2结点-放行");
                    sna = ""; snb = "";
                    flag = false;
                    return 0;   //返回
                }
            }
            #endregion



            //B区第二行存在同类
            if (Caver.SearchClassReferenceBRow2(ref cEigenvector).Count != 0)
            {
                Log4Net.MsgInfo("B2行-存在同类：" + cEigenvector.StringEigenvector);
                //二行就存在同类
                if (CPLCControl.LAD_CheckCell_(PLC.mHandBusy_B2) == 1)
                {
                    Log4Net.MsgInfo("B2模组-空闲");
                    //CPLCControl.LAD_SetDblCell_(PLC.dCave2_B, 2);        //结点准备
                    #region 转值
                    int nunmber = Caver.SearchClassReferenceBRow2(ref cEigenvector)[0];
                    Caver.CaverModelNumber_ProgrammeWarehousing_(nunmber, sna, snb);
                    CPLCControl.LAD_SetDblCell_(PLC.dCave2_B, (short)(20 + nunmber % 10));
                    #endregion
                    Log4Net.MsgInfo("B2结点-开启顶升");
                    Log4Net.MsgInfo("B2行-同类入仓");
                    sna = ""; snb = "";
                    flag = false;
                    return 1;
                }
                else
                {
                    if (Caver.SearchClassReferenceBRow3(ref cEigenvector).Count != 0)
                    {
                        Log4Net.MsgInfo("B2模组-忙，B3行存在同类");
                        CPLCControl.LAD_SetDblCell_(PLC.dCave2_B, 3);
                        Log4Net.MsgInfo("B2结点-放行");
                        sna = ""; snb = "";
                        flag = false;
                        return 0;   //返回
                    }
                    else
                    {
                        //后排无同类
                        if (Caver.SearchVacancyBRow3().Count != 0)
                        {
                            Log4Net.MsgInfo("B2模组-忙，B3都不存在同类，后排存在空位");
                            //TODU:考虑实例激增的方法

                            #region 实例增加

                            int num = Caver.SearchVacancyBRow3()[0];
                            Log4Net.MsgInfo("B3行-新类注册空仓" + num);
                            Caver.CaverModelNumber_Eigenvector(num, ref cEigenvector);
                            CaverBuffData.WriteCaverEigenvector(num, ref cEigenvector);

                            #endregion 实例增加

                            Log4Net.MsgInfo("B区-同类仓增加：" + cEigenvector.StringEigenvector);
                            CPLCControl.LAD_SetDblCell_(PLC.dCave2_B, 3);
                            Log4Net.MsgInfo("B2结点-放行");
                            sna = ""; snb = "";
                            flag = false;
                            return 0;   //返回
                        }
                        else
                        {
                            if (CPLCControl.LAD_CheckCell_(PLC.mHandBusy_B2) == 1)
                            {
                                Log4Net.MsgInfo("B2模组忙-B3都不存在同类，后排无空位");
                                Log4Net.MsgInfo("B2行-等待模组空闲");
                                //二行模组空闲
                                //CPLCControl.LAD_SetDblCell_(PLC.dCave2_B, 2);        //结点准备
                                #region 转值
                                int nunmber = Caver.SearchClassReferenceBRow2(ref cEigenvector)[0];
                                Caver.CaverModelNumber_ProgrammeWarehousing_(nunmber, sna, snb);
                                CPLCControl.LAD_SetDblCell_(PLC.dCave2_B, (short)(20 + nunmber % 10));
                                #endregion
                                Log4Net.MsgInfo("B2结点-开启顶升");
                                sna = ""; snb = "";
                                flag = false;
                                return 1;
                            }
                            return 1;
                        }
                    }
                }
            }
            //TODU:逆向判断-后排同类但模组忙-小时段内单一集中类型进入
            else if (Caver.SearchVacancyBRow2().Count != 0)
            {
                Log4Net.MsgInfo("B2行-不存在同类，B2存在空位");
                if (CPLCControl.LAD_CheckCell_(PLC.mHandBusy_B3) != 1 || SG.CaveSGB3ing || SensorBit(10))
                {
                    Log4Net.MsgInfo("B3行-忙" + "B3行-存在任务");
                    #region 实例增加

                    if (Caver.SearchVacancyBRow2().Count != 0)
                    {
                        int num = Caver.SearchVacancyBRow2()[0];
                        Log4Net.MsgInfo("B1行-新类注册空仓" + num);
                        Caver.CaverModelNumber_Eigenvector(num, ref cEigenvector);
                        CaverBuffData.WriteCaverEigenvector(num, ref cEigenvector);
                    }

                    #endregion 实例增加
                    //CPLCControl.LAD_SetDblCell_(PLC.dCave2_B, 2);
                    #region 转值
                    int nunmber = Caver.SearchClassReferenceBRow2(ref cEigenvector)[0];
                    Caver.CaverModelNumber_ProgrammeWarehousing_(nunmber, sna, snb);
                    CPLCControl.LAD_SetDblCell_(PLC.dCave2_B, (short)(20 + nunmber % 10));
                    #endregion
                    Log4Net.MsgInfo("B2结点-开启顶升");
                    Log4Net.MsgInfo("B2行-同类入仓");
                    sna = ""; snb = "";
                    flag = false;
                    return 1;
                }
                else
                {
                    #region 正向判断-“方法段”
                    if (Caver.SearchClassReferenceBRow3(ref cEigenvector).Count != 0)
                    {
                        Log4Net.MsgInfo("B2行-不存在同类，B3存在同类");
                        CPLCControl.LAD_SetDblCell_(PLC.dCave2_B, 3);
                        Log4Net.MsgInfo("B2结点-放行");
                        sna = ""; snb = "";
                        flag = false;
                        return 0;   //返回
                    }
                    else
                    {
                        Log4Net.MsgInfo("B2行-不存在同类，B3不存在同类");
                        if (Caver.SearchVacancyBRow2().Count != 0)
                        {
                            Log4Net.MsgInfo("B2行-存在空位");
                            //TODU:考虑实例激增的方法

                            #region 实例增加

                            int num = Caver.SearchVacancyBRow2()[0];
                            Log4Net.MsgInfo("B2行-新类注册空仓" + num);
                            Caver.CaverModelNumber_Eigenvector(num, ref cEigenvector);
                            CaverBuffData.WriteCaverEigenvector(num, ref cEigenvector);

                            #endregion 实例增加

                            Log4Net.MsgInfo("B区-同类仓增加：" + cEigenvector.StringEigenvector);
                            //CPLCControl.LAD_SetDblCell_(PLC.dCave2_B, 2);
                            #region 转值
                            int nunmber = Caver.SearchClassReferenceBRow2(ref cEigenvector)[0];
                            Caver.CaverModelNumber_ProgrammeWarehousing_(nunmber, sna, snb);
                            CPLCControl.LAD_SetDblCell_(PLC.dCave2_B, (short)(20 + nunmber % 10));
                            #endregion
                            Log4Net.MsgInfo("B2结点-顶升");
                            sna = ""; snb = "";
                            flag = false;
                            return 1;
                        }
                        else if (Caver.SearchVacancyBRow3().Count != 0)
                        {
                            Log4Net.MsgInfo("B3行-存在空位");
                            //TODU:考虑实例激增的方法

                            #region 实例增加

                            int num = Caver.SearchVacancyBRow3()[0];
                            Log4Net.MsgInfo("B3行-新类注册空仓" + num);
                            Caver.CaverModelNumber_Eigenvector(num, ref cEigenvector);
                            CaverBuffData.WriteCaverEigenvector(num, ref cEigenvector);

                            #endregion 实例增加

                            Log4Net.MsgInfo("B区-同类仓增加：" + cEigenvector.StringEigenvector);
                            CPLCControl.LAD_SetDblCell_(PLC.dCave2_B, 3);
                            Log4Net.MsgInfo("B2结点-放行");
                            sna = ""; snb = "";
                            flag = false;
                            return 0;   //返回
                        }
                        else
                        {
                            Log4Net.MsgInfo("B2行-不存在同类，B3不存在同类-B2B3无空位");
                            CPLCControl.LAD_SetDblCell_(PLC.dCave2_B, 3);
                            Log4Net.MsgInfo("B2结点-放行");
                            sna = ""; snb = "";
                            flag = false;
                            return 0;   //返回
                        }
                    }
                    #endregion

                }
            }
            #region 正向判断-“方法段”
            if (Caver.SearchClassReferenceBRow3(ref cEigenvector).Count != 0)
            {
                Log4Net.MsgInfo("B2行-不存在同类，B3存在同类");
                CPLCControl.LAD_SetDblCell_(PLC.dCave2_B, 3);
                Log4Net.MsgInfo("B2结点-放行");
                sna = ""; snb = "";
                flag = false;
                return 0;   //返回
            }
            else
            {
                Log4Net.MsgInfo("B2行-不存在同类，B3不存在同类");
                if (Caver.SearchVacancyBRow2().Count != 0)
                {
                    Log4Net.MsgInfo("B2行-存在空位");
                    //TODU:考虑实例激增的方法

                    #region 实例增加

                    int num = Caver.SearchVacancyBRow2()[0];
                    Log4Net.MsgInfo("B2行-新类注册空仓" + num);
                    Caver.CaverModelNumber_Eigenvector(num, ref cEigenvector);
                    CaverBuffData.WriteCaverEigenvector(num, ref cEigenvector);

                    #endregion 实例增加

                    Log4Net.MsgInfo("B区-同类仓增加：" + cEigenvector.StringEigenvector);
                   // CPLCControl.LAD_SetDblCell_(PLC.dCave2_B, 2);
                    #region 转值
                    int nunmber = Caver.SearchClassReferenceBRow2(ref cEigenvector)[0];
                    Caver.CaverModelNumber_ProgrammeWarehousing_(nunmber, sna, snb);
                    CPLCControl.LAD_SetDblCell_(PLC.dCave2_B, (short)(20 + nunmber % 10));
                    #endregion
                    Log4Net.MsgInfo("B2结点-顶升");
                    sna = ""; snb = "";
                    flag = false;
                    return 1;
                }
                else if (Caver.SearchVacancyBRow3().Count != 0)
                {
                    Log4Net.MsgInfo("B3行-存在空位");
                    //TODU:考虑实例激增的方法

                    #region 实例增加

                    int num = Caver.SearchVacancyBRow3()[0];
                    Log4Net.MsgInfo("B3行-新类注册空仓" + num);
                    Caver.CaverModelNumber_Eigenvector(num, ref cEigenvector);
                    CaverBuffData.WriteCaverEigenvector(num, ref cEigenvector);

                    #endregion 实例增加

                    Log4Net.MsgInfo("B区-同类仓增加：" + cEigenvector.StringEigenvector);
                    CPLCControl.LAD_SetDblCell_(PLC.dCave2_B, 3);
                    Log4Net.MsgInfo("B2结点-放行");
                    sna = ""; snb = "";
                    flag = false;
                    return 0;   //返回
                }
                else
                {
                    Log4Net.MsgInfo("B2行-不存在同类，B3不存在同类-B2B3无空位");
                    CPLCControl.LAD_SetDblCell_(PLC.dCave2_B, 3);
                    Log4Net.MsgInfo("B2结点-放行");
                    sna = ""; snb = "";
                    flag = false;
                    return 0;   //返回
                }
            }
            #endregion
        }

        /// <summary>
        /// 末尾排
        /// </summary>
        /// <param name="cEigenvector"></param>
        /// <param name="sna"></param>
        /// <param name="snb"></param>
        public static byte ArrangeA3(ref CEigenvector cEigenvector, ref string sna, ref string snb, ref bool flag)
        {
            //A区第三行存在同类
            if (Caver.SearchClassReferenceARow3(ref cEigenvector).Count != 0)
            {
                Log4Net.MsgInfo("A3行-存在同类：" + cEigenvector.StringEigenvector);
                if (CPLCControl.LAD_CheckCell(PLC.mHandBusy_A3) == 1)
                {
                    Log4Net.MsgInfo("A3模组-空闲");
                    //CPLCControl.LAD_SetDblCell(PLC.dCave3_A, 2);        //结点准备
                    #region 转值
                    int nunmber = Caver.SearchClassReferenceARow3(ref cEigenvector)[0];
                    Caver.CaverModelNumber_ProgrammeWarehousing_(nunmber, sna, snb);
                    CPLCControl.LAD_SetDblCell(PLC.dCave3_A, (short)(20 + nunmber % 10));
                    #endregion
                    Log4Net.MsgInfo("A3结点-开启顶升");
                    Log4Net.MsgInfo("A3行-同类入仓");
                    sna = ""; snb = "";
                    flag = false;
                    return 1;
                }
                return 1;
            }
            else
            {
                if (Caver.SearchVacancyARow3().Count != 0)
                {
                    Log4Net.MsgInfo("A3行-不存在同类,存在空位");
                    //TODU:考虑实例激增的方法

                    #region 实例增加

                    int num = Caver.SearchVacancyARow3()[0];
                    Log4Net.MsgInfo("A3行-新类注册空仓" + num);
                    Caver.CaverModelNumber_Eigenvector(num, ref cEigenvector);
                    CaverBuffData.WriteCaverEigenvector(num, ref cEigenvector);

                    #endregion 实例增加

                    Log4Net.MsgInfo("A区-同类仓增加：" + cEigenvector.StringEigenvector);
                    //CPLCControl.LAD_SetDblCell(PLC.dCave3_A, 2);        //结点准备
                    #region 转值
                    int nunmber = Caver.SearchClassReferenceARow3(ref cEigenvector)[0];
                    Caver.CaverModelNumber_ProgrammeWarehousing_(nunmber, sna, snb);
                    CPLCControl.LAD_SetDblCell(PLC.dCave3_A, (short)(20 + nunmber % 10));
                    #endregion
                    sna = ""; snb = "";
                    flag = false;
                    return 1;
                }
                else
                {
                    CPLCControl.LAD_SetDblCell(PLC.dCave3_A, 3);        //结点准备
                    sna = ""; snb = "";
                    flag = false;
                    return 0;
                }
                return 0;
            }
        }

        public static byte ArrangeB3(ref CEigenvector cEigenvector, ref string sna, ref string snb, ref bool flag)
        {
            //B区第三行存在同类
            if (Caver.SearchClassReferenceBRow3(ref cEigenvector).Count != 0)
            {
                Log4Net.MsgInfo("B3行-存在同类：" + cEigenvector.StringEigenvector);
                if (CPLCControl.LAD_CheckCell_(PLC.mHandBusy_B3) == 1)
                {
                    Log4Net.MsgInfo("B3模组-空闲");
                    //CPLCControl.LAD_SetDblCell_(PLC.dCave3_B, 2);        //结点准备
                    #region 转值
                    int nunmber = Caver.SearchClassReferenceBRow3(ref cEigenvector)[0];
                    Caver.CaverModelNumber_ProgrammeWarehousing_(nunmber, sna, snb);
                    CPLCControl.LAD_SetDblCell_(PLC.dCave3_B, (short)(20 + nunmber % 10));
                    #endregion
                    Log4Net.MsgInfo("B3结点-开启顶升");
                    Log4Net.MsgInfo("B3行-同类入仓");
                    sna = ""; snb = "";
                    flag = false;
                    return 1;
                }
                return 1;
            }
            else
            {
                if (Caver.SearchVacancyBRow3().Count != 0)
                {
                    Log4Net.MsgInfo("B3行-不存在同类,存在空位");
                    //TODU:考虑实例激增的方法

                    #region 实例增加

                    int num = Caver.SearchVacancyBRow3()[0];
                    Log4Net.MsgInfo("B3行-新类注册空仓" + num);
                    Caver.CaverModelNumber_Eigenvector(num, ref cEigenvector);
                    CaverBuffData.WriteCaverEigenvector(num, ref cEigenvector);

                    #endregion 实例增加

                    Log4Net.MsgInfo("B区-同类仓增加：" + cEigenvector.StringEigenvector);
                    //CPLCControl.LAD_SetDblCell_(PLC.dCave3_B, 2);        //结点准备
                    #region 转值
                    int nunmber = Caver.SearchClassReferenceBRow3(ref cEigenvector)[0];
                    Caver.CaverModelNumber_ProgrammeWarehousing_(nunmber, sna, snb);
                    CPLCControl.LAD_SetDblCell_(PLC.dCave3_B, (short)(20 + nunmber % 10));
                    #endregion
                    sna = ""; snb = "";
                    flag = false;
                    return 1;
                }
                else
                {
                    CPLCControl.LAD_SetDblCell_(PLC.dCave3_B, 3);        //结点准备
                    Log4Net.MsgInfo("末尾索引空");
                    sna = ""; snb = "";
                    flag = false;
                    return 0;
                }
                return 0;
            }
        }

        #endregion 分类区存在同类

        #region 分类区无同类-实时指定首行新仓类型或预先指定后排仓类型-赋值仓类型的唯一方法

        private static byte NewArrangeA(ref CEigenvector cEigenvector, ref string sna, ref string snb, ref bool flag)
        {
            if (Caver.SearchClassReferenceA(ref cEigenvector).Count == 0)
            {
                Log4Net.MsgInfo("A区-无同类");
                if (Caver.SearchVacancyARow1().Count != 0 && CPLCControl.LAD_CheckCell_(PLC.mHandBusy_A1) == 1)
                {
                    Log4Net.MsgInfo("A1行-存在空位");
                    int num = Caver.SearchVacancyARow1()[0];  //空仓号
                    Log4Net.MsgInfo("A1行-新类注册空仓" + num);
                    Caver.CaverModelNumber_Eigenvector(num, ref cEigenvector);      //注册特征给仓
                    CaverBuffData.WriteCaverEigenvector(num, ref cEigenvector);     //记录仓特征
                                                                                    //CPLCControl.LAD_SetDblCell_(PLC.dCave1_A, 2);        //结点准备
                    //
                    int nunmber = Caver.SearchClassReferenceARow1(ref cEigenvector)[0];
                    Caver.CaverModelNumber_ProgrammeWarehousing_(nunmber, sna, snb);
                    CPLCControl.LAD_SetDblCell_(PLC.dCave1_A, (short)(20 + nunmber % 10));
                    //
                    Log4Net.MsgInfo("A1结点-开启顶升");
                    sna = ""; snb = "";
                    flag = false;
                    return 1;
                }
                else if (Caver.SearchVacancyARow2().Count != 0 || Caver.SearchVacancyARow3().Count != 0)
                {
                    Log4Net.MsgInfo("A1行-不存在空位，A2A3存在空位");
                    if (Caver.SearchVacancyARow3().Count != 0)
                    {
                        int num = Caver.SearchVacancyARow3()[0];
                        Log4Net.MsgInfo("A3行-新类注册空仓" + num);
                        Caver.CaverModelNumber_Eigenvector(num, ref cEigenvector);
                        CaverBuffData.WriteCaverEigenvector(num, ref cEigenvector);

                    }
                    else
                    {
                        int num = Caver.SearchVacancyARow2()[0];
                        Log4Net.MsgInfo("A2行-新类注册空仓" + num);
                        Caver.CaverModelNumber_Eigenvector(num, ref cEigenvector);
                        CaverBuffData.WriteCaverEigenvector(num, ref cEigenvector);
                    }
                    CPLCControl.LAD_SetDblCell_(PLC.dCave1_A, 3);
                    Log4Net.MsgInfo("A1结点-放行");
                    sna = ""; snb = "";
                    flag = false;
                    return 0;   //返回
                }
                else
                {
                    Log4Net.MsgInfo("新类型阻塞！！！");
                    CPLCControl.LAD_SetDblCell_(PLC.dCave1_A, 3);
                    sna = ""; snb = "";
                    flag = false;
                    return 100;
                }
            }
            return 100;
        }

        private static byte NewArrangeB(ref CEigenvector cEigenvector, ref string sna, ref string snb, ref bool flag)
        {
            if (Caver.SearchClassReferenceB(ref cEigenvector).Count == 0)
            {
                Log4Net.MsgInfo("B区-无同类");
                if (Caver.SearchVacancyBRow1().Count != 0 && CPLCControl.LAD_CheckCell_(PLC.mHandBusy_B1) == 1)
                {
                    Log4Net.MsgInfo("B1行-存在空位");
                    int num = Caver.SearchVacancyBRow1()[0];  //空仓号
                    Log4Net.MsgInfo("B1行-新类注册空仓" + num);
                    Caver.CaverModelNumber_Eigenvector(num, ref cEigenvector);      //注册特征给仓
                    CaverBuffData.WriteCaverEigenvector(num, ref cEigenvector);     //记录仓特征
                    //CPLCControl.LAD_SetDblCell_(PLC.dCave1_B, 2);        //结点准备
                    #region 转值
                    int nunmber = Caver.SearchClassReferenceBRow1(ref cEigenvector)[0];
                    Caver.CaverModelNumber_ProgrammeWarehousing_(nunmber, sna, snb);
                    CPLCControl.LAD_SetDblCell_(PLC.dCave1_B, (short)(20 + nunmber % 10));
                    #endregion
                    Log4Net.MsgInfo("B1结点-开启顶升");
                    sna = ""; snb = "";
                    flag = false;
                    return 1;
                }
                else if (Caver.SearchVacancyBRow2().Count != 0 || Caver.SearchVacancyBRow3().Count != 0)
                {
                    Log4Net.MsgInfo("B1行-不存在空位，B2B3存在空位");
                    if (Caver.SearchVacancyBRow3().Count != 0)
                    {
                        int num = Caver.SearchVacancyBRow3()[0];
                        Log4Net.MsgInfo("B3行-新类注册空仓" + num);
                        Caver.CaverModelNumber_Eigenvector(num, ref cEigenvector);
                        CaverBuffData.WriteCaverEigenvector(num, ref cEigenvector);
                    }
                    else
                    {
                        int num = Caver.SearchVacancyBRow2()[0];
                        Log4Net.MsgInfo("B2行-新类注册空仓" + num);
                        Caver.CaverModelNumber_Eigenvector(num, ref cEigenvector);
                        CaverBuffData.WriteCaverEigenvector(num, ref cEigenvector);
                    }
                    CPLCControl.LAD_SetDblCell_(PLC.dCave1_B, 3);
                    Log4Net.MsgInfo("B1结点-放行");
                    sna = ""; snb = "";
                    flag = false;
                    return 0;   //返回
                }
                else
                {
                    Log4Net.MsgInfo("新类型阻塞！！！");
                    CPLCControl.LAD_SetDblCell_(PLC.dCave1_B, 3);
                    sna = ""; snb = "";
                    flag = false;
                    return 100;
                }
            }
            return 100;
        }

        #endregion 分类区无同类-实时指定首行新仓类型或预先指定后排仓类型-赋值仓类型的唯一方法

        #endregion 分类区方法

        #region 特征方法
        /// <summary>
        /// 由数据库索引特征
        /// </summary>
        /// <param name="usn"></param>
        /// <param name="cEigenvector"></param>
        public static void InquireEig(string usn,ref CEigenvector cEigenvector)
        {
            string eig = "";        //特征变量
            cEigenvector = new CEigenvector(LINE.ZERO, "", KCAndBF.ZERO, Remark.ZERO);     //特征类
            MySqlFunction.TrayCellDataList.TrayCellDataList__Eigenvector_SELECT(usn, usn, ref eig);         //查询特征
            if (eig == "")
            {
                Log4Net.MsgInfo("特征索引为空");
                return;
            }
            Log4Net.MsgInfo("特征索引" + eig);
            CEigenvector.EigenvectorString2C(eig, ref cEigenvector);            //字符串转特征类
        }
        #endregion

        #region 关机处理

        public static void ThisOff()
        {
            while (MergeAutoMain.ThisClose)
            {
                Thread.Sleep(100);
            }
        }

        #endregion 关机处理

        #region 外围结点方法

        /// <summary>
        /// 分类区出口扫码
        /// </summary>
        public static void ClassifyExitSG()
        {
            if (CPLCControl.LAD_GetDblCell_(PLC.dClassifyExit_SQRC) == 1 && !SG.ExitSGing)
            {
                SG.ExitSGQRCode = "";
                SG.ExitSGAction.BeginInvoke(null,null);
                SG.ExitSGing = true;
                Log4Net.MsgInfo("回流入口/分类区出口扫码");

                IAsyncResult ClassifyExitSGAsyRes = AutoFuncion.ClassifyExitQRCodeDisposeAction.BeginInvoke(null, null);
            }

            if (CPLCControl.LAD_GetDblCell_(PLC.dClassifyExit_SQRC) != 1)
            {
                SG.ExitSGing = false;
            }
        }

        /// <summary>
        /// 分类出口/回流线入口扫码处理
        /// </summary>
        public static void ClassifyExitQRCodeDispose()
        {
            if (SG.ExitSGing)
            {
                Thread.Sleep((int)SG.Timeout);
                #region 有效扫码-主线

                if (SG.ExitSGQRCode.Length == SG.EffeLength)
                {
                    int ori = 0;
                    string mess = "";
                    MySqlFunction.PackageOrientation.PackageOrientation_SELECT(SG.ExitSGQRCode, ref ori, ref mess);         //获取流向
                    //SG.ExitSGing = false;
                    switch (ori)
                    {
                        case 0:
                            CPLCControl.LAD_SetDblCell(PLC.dClassifyExit_SQRC, 3);      //回流人工区
                            Log4Net.MsgInfo(SG.ExitSGQRCode + "回流人工区" + mess);
                            break;
                        case 1:
                        case 2:
                        case 3:
                        case 4:
                        case 5:
                        case 6:
                        case 31:
                        case 32:
                            CPLCControl.LAD_SetDblCell(PLC.dClassifyExit_SQRC, 3);      //回流人工区
                            Log4Net.MsgInfo(SG.ExitSGQRCode + "回流人工区" + mess);
                            break;
                        case 25:
                        case 24:

                            #region MyRegion
                            string Model = "";
                            ProductCellData ProductCell = new ProductCellData() { usn = "", usnInfo = new string[20], bin = new string[10] };
                            try
                            {

                                SFCSDataDispose.GetKeyInfoFromView_DataDispose(SG.ExitSGQRCode, ref ProductCell.usn, ref ProductCell.usnInfo, ref ProductCell.bin);

                                if (ProductCell.usnInfo[3].Length == 2)
                                {
                                    Model = ProductCell.usnInfo[3].Substring(0, 2);
                                    if (Model == "X8")
                                    {
                                        CPLCControl.LAD_SetDblCell(PLC.dClassifyExit_SQRC, 2);      //流向包装区-打包唯一标识24
                                        Log4Net.MsgInfo(SG.ExitSGQRCode + "流向包装区");
                                    }
                                }
                                else
                                {
                                    Model = ProductCell.usnInfo[3].Substring(0, 3);

                                    if (Model == "X13")
                                    {
                                        CPLCControl.LAD_SetDblCell(PLC.dClassifyExit_SQRC, 4);      //流向包装区-打包唯一标识24
                                        Log4Net.MsgInfo(SG.ExitSGQRCode + "X13流向包装A区");
                                    }
                                    else
                                    {
                                        CPLCControl.LAD_SetDblCell(PLC.dClassifyExit_SQRC, 2);      //流向包装区-打包唯一标识24
                                        Log4Net.MsgInfo(SG.ExitSGQRCode + "流向包装区");
                                    }
                                }


                            }
                            catch
                            {
                                //CPLCControl.LAD_SetDblCell_(PLC.dClassifyExit_SQRC, 4);
                            }
                            #endregion


                            //if (ClassifyExitShunt(SG.ExitSGQRCode))
                            //{
                            //    CPLCControl.LAD_SetDblCell_(PLC.dClassifyExit_SQRC, 4);      //流向包装区-打包唯一标识24
                            //    Log4Net.MsgInfo(SG.ExitSGQRCode + "X13流向包装A区");
                            //}
                            //else
                            //{
                            //    CPLCControl.LAD_SetDblCell_(PLC.dClassifyExit_SQRC, 2);      //流向包装区-打包唯一标识24
                            //    Log4Net.MsgInfo(SG.ExitSGQRCode + "流向包装区");
                            //}
                            break;
                        default:
                            //if (ClassifyExitShunt(SG.ExitSGQRCode))
                            //{
                            //    CPLCControl.LAD_SetDblCell_(PLC.dClassifyExit_SQRC, 4);      //流向包装区-打包唯一标识24
                            //    Log4Net.MsgInfo(SG.ExitSGQRCode + "X13流向包装A区");
                            //}
                            //else
                            //{
                            //    CPLCControl.LAD_SetDblCell_(PLC.dClassifyExit_SQRC, 2);      //流向包装区-打包唯一标识24
                            //    Log4Net.MsgInfo(SG.ExitSGQRCode + "流向包装区");
                            //}
                            string Model_ = "";
                            ProductCellData ProductCell_ = new ProductCellData() { usn = "", usnInfo = new string[20], bin = new string[10] };
                            try
                            {
                                
                                SFCSDataDispose.GetKeyInfoFromView_DataDispose(SG.ExitSGQRCode, ref ProductCell_.usn, ref ProductCell_.usnInfo, ref ProductCell_.bin);

                                if (ProductCell_.usnInfo[3].Length == 2)
                                {
                                    Model = ProductCell_.usnInfo[3].Substring(0, 2);
                                    if (Model == "X8")
                                    {
                                        CPLCControl.LAD_SetDblCell(PLC.dClassifyExit_SQRC, 2);      //流向包装区-打包唯一标识24
                                        Log4Net.MsgInfo(SG.ExitSGQRCode + "流向包装区");
                                    }
                                }
                                else
                                {
                                    Model = ProductCell_.usnInfo[3].Substring(0, 3);

                                    if (Model == "X13")
                                    {
                                        CPLCControl.LAD_SetDblCell(PLC.dClassifyExit_SQRC, 4);      //流向包装区-打包唯一标识24
                                        Log4Net.MsgInfo(SG.ExitSGQRCode + "X13流向包装A区");
                                    }
                                    else
                                    {
                                        CPLCControl.LAD_SetDblCell(PLC.dClassifyExit_SQRC, 2);      //流向包装区-打包唯一标识24
                                        Log4Net.MsgInfo(SG.ExitSGQRCode + "流向包装区");
                                    }
                                }


                            }
                            catch 
                            {
                                //CPLCControl.LAD_SetDblCell_(PLC.dClassifyExit_SQRC, 4);
                            }

                            //CPLCControl.LAD_SetDblCell_(PLC.dClassifyExit_SQRC, 4);
                            //Log4Net.MsgInfo(SG.ExitSGQRCode + "流向包装区");
                            break;
                    }

                    SG.ExitSGQRCode = "";
                }

                #endregion 有效扫码-主线

                #region 码异常

                else if (SG.ExitSGQRCode != "")
                {
                    Log4Net.MsgInfo("分类区扫码超时");
                    CPLCControl.LAD_SetDblCell(PLC.dClassifyExit_SQRC, 3);
                    //SG.ExitSGing = false;
                    SG.ExitSGQRCode = "";
                }

                #endregion 码异常
            }
        }
        public static Action ClassifyExitQRCodeDisposeAction = () => { ClassifyExitQRCodeDispose(); };
        /// <summary>
        /// 回流线出口
        /// </summary>
        public static void BackflowExitSG()
        {
            if (CPLCControl.LAD_GetDblCell_(PLC.dBackflowExit_SQRC) == 1 && !SG.BackflowExitSGing)
            {
                SG.BackflowExitSGQRCode = "";
                SG.BackflowExitSGAciton.BeginInvoke(null, null);
                SG.BackflowExitSGing = true;
                Log4Net.MsgInfo("回流线出口扫码");

                IAsyncResult BackflowExitSGAsyRes = AutoFuncion.BackflowExitQRCodeDisposeAction.BeginInvoke(null, null);

            }
            if (CPLCControl.LAD_GetDblCell_(PLC.dBackflowExit_SQRC) != 1)
            {
                SG.BackflowExitSGing = false;
            }
        }
        public static Action BackflowExitQRCodeDisposeAction = () => { BackflowExitQRCodeDispose(); };
        public static void BackflowExitQRCodeDispose()
        {
            if (SG.BackflowExitSGing)
            {
                Thread.Sleep((int)SG.Timeout);
                #region 有效扫码-主线

                if (SG.BackflowExitSGQRCode.Length == SG.EffeLength)
                {
                    int ori = 0;
                    string mess = "";
                    MySqlFunction.PackageOrientation.PackageOrientation_SELECT(SG.BackflowExitSGQRCode, ref ori, ref mess);         //获取流向
                    MySqlFunction.PackageOrientation.PackageOrientation_UPDATE(SG.BackflowExitSGQRCode, 25, "人工处理");            //流入人工区的刷新流向，允许人工处理后由人工区投入包装区（关键值：25）


                    ProductCellData ProductCell = new ProductCellData() { usn = "", usnInfo = new string[20], bin = new string[10] };
                    Commonality.Model.Tray.TrayModel trayModel = Commonality.Model.Tray.TrayModel.NULL;
                    try
                    {

                        SFCSDataDispose.GetKeyInfoFromView_DataDispose(SG.BackflowExitSGQRCode, ref ProductCell.usn, ref ProductCell.usnInfo, ref ProductCell.bin);
                        SFCSDataDispose.ProductCellData_Model(ProductCell, ref trayModel);
                    }
                    catch
                    {
                        Log4Net.MsgInfo("回流线出口SFC访问异常");
                        CPLCControl.LAD_SetDblCell(PLC.dBackflowExit_SQRC, 32);
                        Log4Net.MsgInfo(SG.ExitSGQRCode + "人工:->32");
                        SG.BackflowExitSGQRCode = "";
                        //SG.BackflowExitSGing = false;
                    }
                    switch (trayModel)
                    {
                        case Commonality.Model.Tray.TrayModel.NULL:
                            break;
                        case Commonality.Model.Tray.TrayModel.X01:
                            CPLCControl.LAD_SetDblCell(PLC.dBackflowExit_SQRC, 11);
                            Log4Net.MsgInfo(SG.BackflowExitSGQRCode + "人工:->" + ori);
                            break;
                        case Commonality.Model.Tray.TrayModel.X03:
                            CPLCControl.LAD_SetDblCell(PLC.dBackflowExit_SQRC, 12);
                            Log4Net.MsgInfo(SG.BackflowExitSGQRCode + "人工:->" + ori);
                            break;
                        case Commonality.Model.Tray.TrayModel.X05:
                            CPLCControl.LAD_SetDblCell(PLC.dBackflowExit_SQRC, 21);
                            Log4Net.MsgInfo(SG.BackflowExitSGQRCode + "人工:->" + ori);
                            break;
                        case Commonality.Model.Tray.TrayModel.X08:
                            CPLCControl.LAD_SetDblCell(PLC.dBackflowExit_SQRC, 22);
                            Log4Net.MsgInfo(SG.BackflowExitSGQRCode + "人工:->" + ori);
                            break;
                        case Commonality.Model.Tray.TrayModel.X13:
                            CPLCControl.LAD_SetDblCell(PLC.dBackflowExit_SQRC, 31);
                            Log4Net.MsgInfo(SG.BackflowExitSGQRCode + "人工:->" + ori);
                            break;
                        case Commonality.Model.Tray.TrayModel.X15:
                            CPLCControl.LAD_SetDblCell(PLC.dBackflowExit_SQRC, 32);
                            Log4Net.MsgInfo(SG.BackflowExitSGQRCode + "人工:->" + ori);
                            break;
                        case Commonality.Model.Tray.TrayModel.Unknown:
                            CPLCControl.LAD_SetDblCell(PLC.dBackflowExit_SQRC, 32);
                            Log4Net.MsgInfo(SG.BackflowExitSGQRCode + "人工:->" + ori);
                            break;
                        default:
                            CPLCControl.LAD_SetDblCell(PLC.dBackflowExit_SQRC, 32);
                            Log4Net.MsgInfo(SG.BackflowExitSGQRCode + "人工:->" + ori);
                            break;
                    }
                    SG.BackflowExitSGQRCode = "";
                    //SG.BackflowExitSGing = false;
                }

                #endregion 有效扫码-主线

                #region 扫码超时

                else if (SG.BackflowExitSGQRCode != "")
                {
                    Log4Net.MsgInfo("回流线出口扫码超时");
                    CPLCControl.LAD_SetDblCell(PLC.dBackflowExit_SQRC, 32);
                    Log4Net.MsgInfo(SG.ExitSGQRCode + "人工:->32");
                    SG.BackflowExitSGQRCode = "";
                    //SG.BackflowExitSGing = false;
                }

                #endregion 扫码超时
            }
        }

        #endregion 外围结点方法

        private static bool ClassifyExitShunt(string sn)
        {
            ProductCellData productCellData = new ProductCellData();
            MySqlFunction.TrayCellDataList.TrayCellDataList_SELECT(sn, sn, ref productCellData);
            if (productCellData.usnInfo[3].Substring(0,3) == "X13")
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 全区取料位Sensor(D6：L8->1，2，3(0,1,2)；H8->1,2,3(8,9,10))
        /// </summary>
        /// <param name="bit"></param>
        /// <returns></returns>
        public static bool SensorBit(int bit)
        {
            return ((CPLCControl.LAD_GetDblCell_(PLC.dSensor) >> bit & 1) == 1);
        }
    }


    public static class SG
    {
        public static void SGInit()
        {
            EffeLength = ("ABCDEFGHIJKLMNOPR\r\n").Length;
            Timeout = 2400;

            EntranceSGA = new CKeyenceScanningGunModel("COM3", 115200, 8, Parity.None, StopBits.One, EntranceSGA_QRcode);
            EntranceSGB = new CKeyenceScanningGunModel("COM4", 115200, 8, Parity.None, StopBits.One, EntranceSGB_QRcode);

            CaveSGA1 = new CKeyenceScanningGunModel("COM5", 115200, 8, Parity.None, StopBits.One, CaveSGA1_QRcode);
            CaveSGA2 = new CKeyenceScanningGunModel("COM7", 115200, 8, Parity.None, StopBits.One, CaveSGA2_QRcode);
            CaveSGA3 = new CKeyenceScanningGunModel("COM9", 115200, 8, Parity.None, StopBits.One, CaveSGA3_QRcode);
            CaveSGB1 = new CKeyenceScanningGunModel("COM6", 115200, 8, Parity.None, StopBits.One, CaveSGB1_QRcode);
            CaveSGB2 = new CKeyenceScanningGunModel("COM8", 115200, 8, Parity.None, StopBits.One, CaveSGB2_QRcode);
            CaveSGB3 = new CKeyenceScanningGunModel("COM10", 115200, 8, Parity.None, StopBits.One, CaveSGB3_QRcode);

            ExitSG = new CKeyenceScanningGunModel("COM11", 115200, 8, Parity.None, StopBits.One, Exit_QRcode);
            BackflowExitSG = new CKeyenceScanningGunModel("COM12", 115200, 8, Parity.None, StopBits.One, BackflowExit_QRcode);

            EntranceSGAing = false;      //扫码标志
            EntranceSGBing = false;      //扫码标志

            CaveSGA1ing = false;     //扫码标志
            CaveSGA2ing = false;     //扫码标志
            CaveSGA3ing = false;     //扫码标志
            CaveSGB1ing = false;     //扫码标志
            CaveSGB2ing = false;     //扫码标志
            CaveSGB3ing = false;     //扫码标志

            ExitSGing = false;
            BackflowExitSGing = false;

            EntranceSGACRCode = "";
            EntranceSGBCRCode = "";


            CaveSGA1QRCode = "";
            CaveSGA2QRCode = "";
            CaveSGA3QRCode = "";
            CaveSGB1QRCode = "";
            CaveSGB2QRCode = "";
            CaveSGB3QRCode = "";

            ExitSGQRCode = "";
            BackflowExitSGQRCode = "";

            EntranceSGAAction = () => EntranceSGA.ScanCodeTimeout(Timeout);
            EntranceSGBAction = () => EntranceSGB.ScanCodeTimeout(Timeout);

            CaveSGA1Action = () => {CaveSGA1.ScanCodeTimeout(Timeout); };
            CaveSGA2Action = () => CaveSGA2.ScanCodeTimeout(Timeout);
            CaveSGA3Action = () => CaveSGA3.ScanCodeTimeout(Timeout);
            CaveSGB1Action = () => CaveSGB1.ScanCodeTimeout(Timeout);
            CaveSGB2Action = () => CaveSGB2.ScanCodeTimeout(Timeout);
            CaveSGB3Action = () => CaveSGB3.ScanCodeTimeout(Timeout);

            ExitSGAction = () => ExitSG.ScanCodeTimeout(Timeout);
            BackflowExitSGAciton = () => {BackflowExitSG.ScanCodeTimeout(Timeout); };

        }

        public static double Timeout;

        public static CKeyenceScanningGunModel EntranceSGA;
        public static Action EntranceSGAAction;
        public static CKeyenceScanningGunModel EntranceSGB;
        public static Action EntranceSGBAction;

        public static CKeyenceScanningGunModel CaveSGA1;
        public static Action CaveSGA1Action; 
        public static CKeyenceScanningGunModel CaveSGA2;
        public static Action CaveSGA2Action; 
        public static CKeyenceScanningGunModel CaveSGA3;
        public static Action CaveSGA3Action; 
        public static CKeyenceScanningGunModel CaveSGB1;
        public static Action CaveSGB1Action; 
        public static CKeyenceScanningGunModel CaveSGB2;
        public static Action CaveSGB2Action; 
        public static CKeyenceScanningGunModel CaveSGB3;
        public static Action CaveSGB3Action; 

        public static CKeyenceScanningGunModel ExitSG;
        public static Action ExitSGAction;
        public static CKeyenceScanningGunModel BackflowExitSG;
        public static Action BackflowExitSGAciton;

        public static bool EntranceSGAing;      //扫码标志
        public static bool EntranceSGBing;      //扫码标志

        public static bool CaveSGA1ing;     //扫码标志
        public static bool CaveSGA2ing;     //扫码标志
        public static bool CaveSGA3ing;     //扫码标志
        public static bool CaveSGB1ing;     //扫码标志
        public static bool CaveSGB2ing;     //扫码标志
        public static bool CaveSGB3ing;     //扫码标志

        public static bool ExitSGing;       //扫码标志
        public static bool BackflowExitSGing; //

        public static int EffeLength;

        public static string EntranceSGACRCode = "";
        public static string EntranceSGBCRCode = "";


        public static string CaveSGA1QRCode = "";
        public static string CaveSGA2QRCode = "";
        public static string CaveSGA3QRCode = "";
        public static string CaveSGB1QRCode = "";
        public static string CaveSGB2QRCode = "";
        public static string CaveSGB3QRCode = "";

        public static string ExitSGQRCode = "";
        public static string BackflowExitSGQRCode = "";

        public static void EntranceSGA_QRcode(ref string code)
        {
            if (EntranceSGACRCode == "")
            {
                EntranceSGACRCode = code;
                Log4Net.MsgInfo("A分类入口扫码：\r\n" + code);
            }
        }

        public static void EntranceSGB_QRcode(ref string code)
        {
            if (EntranceSGBCRCode == "")
            {
                EntranceSGBCRCode = code;
                Log4Net.MsgInfo("B分类入口扫码：\r\n" + code);
            }
        }

        public static void CaveSGA1_QRcode(ref string code)
        {
            CaveSGA1QRCode = code;
            Log4Net.MsgInfo("A分类模组1扫码：\r\n" + code);
        }

        public static void CaveSGA2_QRcode(ref string code)
        {
            CaveSGA2QRCode = code;
            Log4Net.MsgInfo("A分类模组2扫码：\r\n" + code);
        }

        public static void CaveSGA3_QRcode(ref string code)
        {
            CaveSGA3QRCode = code;
            Log4Net.MsgInfo("A分类模组3扫码：\r\n" + code);
        }

        public static void CaveSGB1_QRcode(ref string code)
        {
            CaveSGB1QRCode = code;
            Log4Net.MsgInfo("B分类模组1扫码：\r\n" + code);
        }

        public static void CaveSGB2_QRcode(ref string code)
        {
            CaveSGB2QRCode = code;
            Log4Net.MsgInfo("B分类模组2扫码：\r\n" + code);
        }

        public static void CaveSGB3_QRcode(ref string code)
        {
            CaveSGB3QRCode = code;
            Log4Net.MsgInfo("B分类模组3扫码：\r\n" + code);
        }

        public static void Exit_QRcode(ref string code)
        {
            ExitSGQRCode = code;
            Log4Net.MsgInfo("回流线/分类区出口扫码：\r\n" + code);
        }

        public static void BackflowExit_QRcode(ref string code)
        {
            BackflowExitSGQRCode = code;
            Log4Net.MsgInfo("回流线出口扫码：\r\n" + code);
        }
    }


    public static class Caver
    {
        public static void CaverInit()
        {
            #region 实例化仓对象

            //实例化A区仓
            CaveA11 = new CaveModel(111, PLC.dCaveStock_A11, PLC.mHandBusy_A1, PLC.dCaveStuation_A11, PLC.dDestination_A1, PLC.dCave1_A, PLC.tCaverA11OldTime);
            CaveA12 = new CaveModel(112, PLC.dCaveStock_A12, PLC.mHandBusy_A1, PLC.dCaveStuation_A12, PLC.dDestination_A1, PLC.dCave1_A, PLC.tCaverA12OldTime);
            CaveA13 = new CaveModel(113, PLC.dCaveStock_A13, PLC.mHandBusy_A1, PLC.dCaveStuation_A13, PLC.dDestination_A1, PLC.dCave1_A, PLC.tCaverA13OldTime);
            CaveA14 = new CaveModel(114, PLC.dCaveStock_A14, PLC.mHandBusy_A1, PLC.dCaveStuation_A14, PLC.dDestination_A1, PLC.dCave1_A, PLC.tCaverA14OldTime);
            CaveA15 = new CaveModel(115, PLC.dCaveStock_A15, PLC.mHandBusy_A1, PLC.dCaveStuation_A15, PLC.dDestination_A1, PLC.dCave1_A, PLC.tCaverA15OldTime);

            CaveA21 = new CaveModel(121, PLC.dCaveStock_A21, PLC.mHandBusy_A2, PLC.dCaveStuation_A21, PLC.dDestination_A2, PLC.dCave2_A, PLC.tCaverA21OldTime);
            CaveA22 = new CaveModel(122, PLC.dCaveStock_A22, PLC.mHandBusy_A2, PLC.dCaveStuation_A22, PLC.dDestination_A2, PLC.dCave2_A, PLC.tCaverA22OldTime);
            CaveA23 = new CaveModel(123, PLC.dCaveStock_A23, PLC.mHandBusy_A2, PLC.dCaveStuation_A23, PLC.dDestination_A2, PLC.dCave2_A, PLC.tCaverA23OldTime);
            CaveA24 = new CaveModel(124, PLC.dCaveStock_A24, PLC.mHandBusy_A2, PLC.dCaveStuation_A24, PLC.dDestination_A2, PLC.dCave2_A, PLC.tCaverA24OldTime);
            CaveA25 = new CaveModel(125, PLC.dCaveStock_A25, PLC.mHandBusy_A2, PLC.dCaveStuation_A25, PLC.dDestination_A2, PLC.dCave2_A, PLC.tCaverA25OldTime);

            CaveA31 = new CaveModel(131, PLC.dCaveStock_A31, PLC.mHandBusy_A3, PLC.dCaveStuation_A31, PLC.dDestination_A3, PLC.dCave3_A, PLC.tCaverA31OldTime);
            CaveA32 = new CaveModel(132, PLC.dCaveStock_A32, PLC.mHandBusy_A3, PLC.dCaveStuation_A32, PLC.dDestination_A3, PLC.dCave3_A, PLC.tCaverA32OldTime);
            CaveA33 = new CaveModel(133, PLC.dCaveStock_A33, PLC.mHandBusy_A3, PLC.dCaveStuation_A33, PLC.dDestination_A3, PLC.dCave3_A, PLC.tCaverA33OldTime);
            CaveA34 = new CaveModel(134, PLC.dCaveStock_A34, PLC.mHandBusy_A3, PLC.dCaveStuation_A34, PLC.dDestination_A3, PLC.dCave3_A, PLC.tCaverA34OldTime);
            CaveA35 = new CaveModel(135, PLC.dCaveStock_A35, PLC.mHandBusy_A3, PLC.dCaveStuation_A35, PLC.dDestination_A3, PLC.dCave3_A, PLC.tCaverA35OldTime);

            //实例化B区仓
            CaveB11 = new CaveModel(211, PLC.dCaveStock_B11, PLC.mHandBusy_B1, PLC.dCaveStuation_B11, PLC.dDestination_B1, PLC.dCave1_B, PLC.tCaverB11OldTime);
            CaveB12 = new CaveModel(212, PLC.dCaveStock_B12, PLC.mHandBusy_B1, PLC.dCaveStuation_B12, PLC.dDestination_B1, PLC.dCave1_B, PLC.tCaverB12OldTime);
            CaveB13 = new CaveModel(213, PLC.dCaveStock_B13, PLC.mHandBusy_B1, PLC.dCaveStuation_B13, PLC.dDestination_B1, PLC.dCave1_B, PLC.tCaverB13OldTime);
            CaveB14 = new CaveModel(214, PLC.dCaveStock_B14, PLC.mHandBusy_B1, PLC.dCaveStuation_B14, PLC.dDestination_B1, PLC.dCave1_B, PLC.tCaverB14OldTime);
            CaveB15 = new CaveModel(215, PLC.dCaveStock_B15, PLC.mHandBusy_B1, PLC.dCaveStuation_B15, PLC.dDestination_B1, PLC.dCave1_B, PLC.tCaverB15OldTime);

            CaveB21 = new CaveModel(221, PLC.dCaveStock_B21, PLC.mHandBusy_B2, PLC.dCaveStuation_B21, PLC.dDestination_B2, PLC.dCave2_B, PLC.tCaverB21OldTime);
            CaveB22 = new CaveModel(222, PLC.dCaveStock_B22, PLC.mHandBusy_B2, PLC.dCaveStuation_B22, PLC.dDestination_B2, PLC.dCave2_B, PLC.tCaverB22OldTime);
            CaveB23 = new CaveModel(223, PLC.dCaveStock_B23, PLC.mHandBusy_B2, PLC.dCaveStuation_B23, PLC.dDestination_B2, PLC.dCave2_B, PLC.tCaverB23OldTime);
            CaveB24 = new CaveModel(224, PLC.dCaveStock_B24, PLC.mHandBusy_B2, PLC.dCaveStuation_B24, PLC.dDestination_B2, PLC.dCave2_B, PLC.tCaverB24OldTime);
            CaveB25 = new CaveModel(225, PLC.dCaveStock_B25, PLC.mHandBusy_B2, PLC.dCaveStuation_B25, PLC.dDestination_B2, PLC.dCave2_B, PLC.tCaverB25OldTime);

            CaveB31 = new CaveModel(231, PLC.dCaveStock_B31, PLC.mHandBusy_B3, PLC.dCaveStuation_B31, PLC.dDestination_B3, PLC.dCave3_B, PLC.tCaverB31OldTime);
            CaveB32 = new CaveModel(232, PLC.dCaveStock_B32, PLC.mHandBusy_B3, PLC.dCaveStuation_B32, PLC.dDestination_B3, PLC.dCave3_B, PLC.tCaverB32OldTime);
            CaveB33 = new CaveModel(233, PLC.dCaveStock_B33, PLC.mHandBusy_B3, PLC.dCaveStuation_B33, PLC.dDestination_B3, PLC.dCave3_B, PLC.tCaverB33OldTime);
            CaveB34 = new CaveModel(234, PLC.dCaveStock_B34, PLC.mHandBusy_B3, PLC.dCaveStuation_B34, PLC.dDestination_B3, PLC.dCave3_B, PLC.tCaverB34OldTime);
            CaveB35 = new CaveModel(235, PLC.dCaveStock_B35, PLC.mHandBusy_B3, PLC.dCaveStuation_B35, PLC.dDestination_B3, PLC.dCave3_B, PLC.tCaverB35OldTime);

            #endregion 实例化仓对象

            //加载仓缓存数据
            CaverBuffData.CaverBuffDataLoad();

            //CaverRuning();
        }

        public static void CaverSelfInspection()
        {
            #region Caver自检

            //A
            Caver.CaveA11.SelfInspection();
            Caver.CaveA12.SelfInspection();
            Caver.CaveA13.SelfInspection();
            Caver.CaveA14.SelfInspection();
            Caver.CaveA15.SelfInspection();

            Caver.CaveA21.SelfInspection();
            Caver.CaveA22.SelfInspection();
            Caver.CaveA23.SelfInspection();
            Caver.CaveA24.SelfInspection();
            Caver.CaveA25.SelfInspection();

            Caver.CaveA31.SelfInspection();
            Caver.CaveA32.SelfInspection();
            Caver.CaveA33.SelfInspection();
            Caver.CaveA34.SelfInspection();
            Caver.CaveA35.SelfInspection();

            //B
            Caver.CaveB11.SelfInspection();
            Caver.CaveB12.SelfInspection();
            Caver.CaveB13.SelfInspection();
            Caver.CaveB14.SelfInspection();
            Caver.CaveB15.SelfInspection();

            Caver.CaveB21.SelfInspection();
            Caver.CaveB22.SelfInspection();
            Caver.CaveB23.SelfInspection();
            Caver.CaveB24.SelfInspection();
            Caver.CaveB25.SelfInspection();

            Caver.CaveB31.SelfInspection();
            Caver.CaveB32.SelfInspection();
            Caver.CaveB33.SelfInspection();
            Caver.CaveB34.SelfInspection();
            Caver.CaveB35.SelfInspection();

            #endregion Caver自检
        }

        public static void CaverLoopCom()
        {


            Leisure();

            OldTimeFuncStartAndStop();
        }
        public static void CaverLoopA()
        {
            CaverA1Loop();
            CaverA2Loop();
            CaverA3Loop();
        }
        public static void CaverLoopB()
        {
            CaverB1Loop();
            CaverB2Loop();
            CaverB3Loop();

        }
        #region 声明仓

        //模组A1
        public static CaveModel CaveA11;

        public static CaveModel CaveA12;
        public static CaveModel CaveA13;
        public static CaveModel CaveA14;
        public static CaveModel CaveA15;

        //模组A2
        public static CaveModel CaveA21;

        public static CaveModel CaveA22;
        public static CaveModel CaveA23;
        public static CaveModel CaveA24;
        public static CaveModel CaveA25;

        //模组A3
        public static CaveModel CaveA31;

        public static CaveModel CaveA32;
        public static CaveModel CaveA33;
        public static CaveModel CaveA34;
        public static CaveModel CaveA35;

        //模组B1
        public static CaveModel CaveB11;

        public static CaveModel CaveB12;
        public static CaveModel CaveB13;
        public static CaveModel CaveB14;
        public static CaveModel CaveB15;

        //模组B1
        public static CaveModel CaveB21;

        public static CaveModel CaveB22;
        public static CaveModel CaveB23;
        public static CaveModel CaveB24;
        public static CaveModel CaveB25;

        //模组B1
        public static CaveModel CaveB31;

        public static CaveModel CaveB32;
        public static CaveModel CaveB33;
        public static CaveModel CaveB34;
        public static CaveModel CaveB35;

        #endregion 声明仓

        #region Caver自动轮询
        public static Action CaverA1LoopAction = () => { CaverA1Loop(); };
        public static void CaverA1Loop()
        {
            //A
            CaveA11.PracticalWarehousing();
            CaveA11.CaveFullEmpty_AutoFunc();
            CaveA12.PracticalWarehousing();
            CaveA12.CaveFullEmpty_AutoFunc();
            CaveA13.PracticalWarehousing();
            CaveA13.CaveFullEmpty_AutoFunc();
            CaveA14.PracticalWarehousing();
            CaveA14.CaveFullEmpty_AutoFunc();
            CaveA15.PracticalWarehousing();
            CaveA15.CaveFullEmpty_AutoFunc();

            CaveA11.CaverSta();
            CaveA12.CaverSta();
            CaveA13.CaverSta();
            CaveA14.CaverSta();
            CaveA15.CaverSta();

            //CaveA11.staCavePLCMemory = 2;
            //CaveA11.staCaveStuation = 2;
            CaverForm.CaverForm.CaverNnumberA11.CaverUI(CaveA11);
            CaverForm.CaverForm.CaverNnumberA12.CaverUI(CaveA12);
            CaverForm.CaverForm.CaverNnumberA13.CaverUI(CaveA13);
            CaverForm.CaverForm.CaverNnumberA14.CaverUI(CaveA14);
            CaverForm.CaverForm.CaverNnumberA15.CaverUI(CaveA15);

            CaveA11.StandbyTime();
            CaveA12.StandbyTime();
            CaveA13.StandbyTime();
            CaveA14.StandbyTime();
            CaveA15.StandbyTime();
        }
        public static Action CaverA2LoopAction = () => { CaverA2Loop(); };
        public static void CaverA2Loop()
        {
            CaveA21.PracticalWarehousing();
            CaveA21.CaveFullEmpty_AutoFunc();
            CaveA22.PracticalWarehousing();
            CaveA22.CaveFullEmpty_AutoFunc();
            CaveA23.PracticalWarehousing();
            CaveA23.CaveFullEmpty_AutoFunc();
            CaveA24.PracticalWarehousing();
            CaveA24.CaveFullEmpty_AutoFunc();
            CaveA25.PracticalWarehousing();
            CaveA25.CaveFullEmpty_AutoFunc();

            CaveA21.CaverSta();
            CaveA22.CaverSta();
            CaveA23.CaverSta();
            CaveA24.CaverSta();
            CaveA25.CaverSta();

            CaverForm.CaverForm.CaverNnumberA21.CaverUI(CaveA21);
            CaverForm.CaverForm.CaverNnumberA22.CaverUI(CaveA22);
            CaverForm.CaverForm.CaverNnumberA23.CaverUI(CaveA23);
            CaverForm.CaverForm.CaverNnumberA24.CaverUI(CaveA24);
            CaverForm.CaverForm.CaverNnumberA25.CaverUI(CaveA25);

            CaveA21.StandbyTime();
            CaveA22.StandbyTime();
            CaveA23.StandbyTime();
            CaveA24.StandbyTime();
            CaveA25.StandbyTime();
        }
        public static Action CaverA3LoopAction = () => { CaverA3Loop(); };
        public static void CaverA3Loop()
        {
            CaveA31.PracticalWarehousing();
            CaveA31.CaveFullEmpty_AutoFunc();
            CaveA32.PracticalWarehousing();
            CaveA32.CaveFullEmpty_AutoFunc();
            CaveA33.PracticalWarehousing();
            CaveA33.CaveFullEmpty_AutoFunc();
            CaveA34.PracticalWarehousing();
            CaveA34.CaveFullEmpty_AutoFunc();
            CaveA35.PracticalWarehousing();
            CaveA35.CaveFullEmpty_AutoFunc();

            CaveA31.CaverSta();
            CaveA32.CaverSta();
            CaveA33.CaverSta();
            CaveA34.CaverSta();
            CaveA35.CaverSta();

            CaverForm.CaverForm.CaverNnumberA31.CaverUI(CaveA31);
            CaverForm.CaverForm.CaverNnumberA32.CaverUI(CaveA32);
            CaverForm.CaverForm.CaverNnumberA33.CaverUI(CaveA33);
            CaverForm.CaverForm.CaverNnumberA34.CaverUI(CaveA34);
            CaverForm.CaverForm.CaverNnumberA35.CaverUI(CaveA35);

            CaveA31.StandbyTime();
            CaveA32.StandbyTime();
            CaveA33.StandbyTime();
            CaveA34.StandbyTime();
            CaveA35.StandbyTime();
        }

        public static void CaverB1Loop()
        {
            //B
            CaveB11.PracticalWarehousing();
            CaveB11.CaveFullEmpty_AutoFunc();
            CaveB12.PracticalWarehousing();
            CaveB12.CaveFullEmpty_AutoFunc();
            CaveB13.PracticalWarehousing();
            CaveB13.CaveFullEmpty_AutoFunc();
            CaveB14.PracticalWarehousing();
            CaveB14.CaveFullEmpty_AutoFunc();
            CaveB15.PracticalWarehousing();
            CaveB15.CaveFullEmpty_AutoFunc();

            CaveB11.CaverSta();
            CaveB12.CaverSta();
            CaveB13.CaverSta();
            CaveB14.CaverSta();
            CaveB15.CaverSta();

            CaverForm.CaverForm.CaverNnumberB11.CaverUI(CaveB11);
            CaverForm.CaverForm.CaverNnumberB12.CaverUI(CaveB12);
            CaverForm.CaverForm.CaverNnumberB13.CaverUI(CaveB13);
            CaverForm.CaverForm.CaverNnumberB14.CaverUI(CaveB14);
            CaverForm.CaverForm.CaverNnumberB15.CaverUI(CaveB15);

            CaveB11.StandbyTime();
            CaveB12.StandbyTime();
            CaveB13.StandbyTime();
            CaveB14.StandbyTime();
            CaveB15.StandbyTime();
        }

        public static void CaverB2Loop()
        {
            CaveB21.PracticalWarehousing();
            CaveB21.CaveFullEmpty_AutoFunc();
            CaveB22.PracticalWarehousing();
            CaveB22.CaveFullEmpty_AutoFunc();
            CaveB23.PracticalWarehousing();
            CaveB23.CaveFullEmpty_AutoFunc();
            CaveB24.PracticalWarehousing();
            CaveB24.CaveFullEmpty_AutoFunc();
            CaveB25.PracticalWarehousing();
            CaveB25.CaveFullEmpty_AutoFunc();

            CaveB21.CaverSta();
            CaveB22.CaverSta();
            CaveB23.CaverSta();
            CaveB24.CaverSta();
            CaveB25.CaverSta();

            CaverForm.CaverForm.CaverNnumberB21.CaverUI(CaveB21);
            CaverForm.CaverForm.CaverNnumberB22.CaverUI(CaveB22);
            CaverForm.CaverForm.CaverNnumberB23.CaverUI(CaveB23);
            CaverForm.CaverForm.CaverNnumberB24.CaverUI(CaveB24);
            CaverForm.CaverForm.CaverNnumberB25.CaverUI(CaveB25);

            CaveB21.StandbyTime();
            CaveB22.StandbyTime();
            CaveB23.StandbyTime();
            CaveB24.StandbyTime();
            CaveB25.StandbyTime();
        }

        public static void CaverB3Loop()
        {
            CaveB31.PracticalWarehousing();
            CaveB31.CaveFullEmpty_AutoFunc();
            CaveB32.PracticalWarehousing();
            CaveB32.CaveFullEmpty_AutoFunc();
            CaveB33.PracticalWarehousing();
            CaveB33.CaveFullEmpty_AutoFunc();
            CaveB34.PracticalWarehousing();
            CaveB34.CaveFullEmpty_AutoFunc();
            CaveB35.PracticalWarehousing();
            CaveB35.CaveFullEmpty_AutoFunc();

            CaveB31.CaverSta();
            CaveB32.CaverSta();
            CaveB33.CaverSta();
            CaveB34.CaverSta();
            CaveB35.CaverSta();

            CaverForm.CaverForm.CaverNnumberB31.CaverUI(CaveB31);
            CaverForm.CaverForm.CaverNnumberB32.CaverUI(CaveB32);
            CaverForm.CaverForm.CaverNnumberB33.CaverUI(CaveB33);
            CaverForm.CaverForm.CaverNnumberB34.CaverUI(CaveB34);
            CaverForm.CaverForm.CaverNnumberB35.CaverUI(CaveB35);

            CaveB31.StandbyTime();
            CaveB32.StandbyTime();
            CaveB33.StandbyTime();
            CaveB34.StandbyTime();
            CaveB35.StandbyTime();
        }
        #endregion

        #region 关于仓位的相关公共方法

        /// <summary>
        /// 搜索分类区A边内同类坐标
        /// </summary>
        /// <param name="cEigenvector"></param>
        /// <returns></returns>
        public static List<int> SearchClassReferenceA(ref CEigenvector cEigenvector)
        {
            List<int> reference = new List<int>();

            #region 收索分类区内相同类型仓的坐标

            //A1
            if (CEigenvector.Comparison(ref cEigenvector, ref CaveA11.Eigenvector))
            {
                if (CaveA11.ContProgramme < 20)
                {
                    reference.Add(CaveA11.CaverModelNumber);
                    return reference;
                }
            }
            if (CEigenvector.Comparison(ref cEigenvector, ref CaveA12.Eigenvector))
            {
                if (CaveA12.ContProgramme < 20)
                {
                    reference.Add(CaveA12.CaverModelNumber);
                    return reference;
                }
            }
            if (CEigenvector.Comparison(ref cEigenvector, ref CaveA13.Eigenvector))
            {
                if (CaveA13.ContProgramme < 20)
                {
                    reference.Add(CaveA13.CaverModelNumber);
                    return reference;
                }
            }
            if (CEigenvector.Comparison(ref cEigenvector, ref CaveA14.Eigenvector))
            {
                if (CaveA14.ContProgramme < 20)
                {
                    reference.Add(CaveA14.CaverModelNumber);
                    return reference;
                }
            }
            if (CEigenvector.Comparison(ref cEigenvector, ref CaveA15.Eigenvector))
            {
                if (CaveA15.ContProgramme < 20)
                {
                    reference.Add(CaveA15.CaverModelNumber);
                    return reference;
                }
            }
            //A2
            if (CEigenvector.Comparison(ref cEigenvector, ref CaveA21.Eigenvector))
            {
                if (CaveA21.ContProgramme < 20)
                {
                    reference.Add(CaveA21.CaverModelNumber);
                    return reference;
                }
            }
            if (CEigenvector.Comparison(ref cEigenvector, ref CaveA22.Eigenvector))
            {
                if (CaveA22.ContProgramme < 20)
                {
                    reference.Add(CaveA22.CaverModelNumber);
                    return reference;
                }
            }
            if (CEigenvector.Comparison(ref cEigenvector, ref CaveA23.Eigenvector))
            {
                if (CaveA23.ContProgramme < 20)
                {
                    reference.Add(CaveA23.CaverModelNumber);
                    return reference;
                }
            }
            if (CEigenvector.Comparison(ref cEigenvector, ref CaveA24.Eigenvector))
            {
                if (CaveA24.ContProgramme < 20)
                {
                    reference.Add(CaveA24.CaverModelNumber);
                    return reference;
                }
            }
            if (CEigenvector.Comparison(ref cEigenvector, ref CaveA25.Eigenvector))
            {
                if (CaveA25.ContProgramme < 20)
                {
                    reference.Add(CaveA25.CaverModelNumber);
                    return reference;
                }
            }
            //A2
            if (CEigenvector.Comparison(ref cEigenvector, ref CaveA31.Eigenvector))
            {
                if (CaveA31.ContProgramme < 20)
                {
                    reference.Add(CaveA31.CaverModelNumber);
                    return reference;
                }
            }
            if (CEigenvector.Comparison(ref cEigenvector, ref CaveA32.Eigenvector))
            {
                if (CaveA32.ContProgramme < 20)
                {
                    reference.Add(CaveA32.CaverModelNumber);
                    return reference;
                }
            }
            if (CEigenvector.Comparison(ref cEigenvector, ref CaveA33.Eigenvector))
            {
                if (CaveA33.ContProgramme < 20)
                {
                    reference.Add(CaveA33.CaverModelNumber);
                    return reference;
                }
            }
            if (CEigenvector.Comparison(ref cEigenvector, ref CaveA34.Eigenvector))
            {
                if (CaveA34.ContProgramme < 20)
                {
                    reference.Add(CaveA34.CaverModelNumber);
                    return reference;
                }
            }
            if (CEigenvector.Comparison(ref cEigenvector, ref CaveA35.Eigenvector))
            {
                if (CaveA35.ContProgramme < 20)
                {
                    reference.Add(CaveA35.CaverModelNumber);
                    return reference;
                }
            }

            #endregion 收索分类区内相同类型仓的坐标
            //cEigenvector = new CEigenvector(LINE.ZERO, "", KCAndBF.ZERO, Remark.ZERO);
            return reference;
        }

        /// <summary>
        /// 搜索分类区B边内同类坐标
        /// </summary>
        /// <param name="cEigenvector"></param>
        /// <returns></returns>
        public static List<int> SearchClassReferenceB(ref CEigenvector cEigenvector)
        {
            List<int> reference = new List<int>();

            #region 收索分类区内相同类型仓的坐标

            //B1
            if (CEigenvector.Comparison(ref cEigenvector, ref CaveB11.Eigenvector))
            {
                if (CaveB11.ContProgramme < 20)
                {
                    reference.Add(CaveB11.CaverModelNumber);
                    return reference;
                }
            }
            if (CEigenvector.Comparison(ref cEigenvector, ref CaveB12.Eigenvector))
            {
                if (CaveB12.ContProgramme < 20)
                {
                    reference.Add(CaveB12.CaverModelNumber);
                    return reference;
                }
            }
            if (CEigenvector.Comparison(ref cEigenvector, ref CaveB13.Eigenvector))
            {
                if (CaveB13.ContProgramme < 20)
                {
                    reference.Add(CaveB13.CaverModelNumber);
                    return reference;
                }
            }
            if (CEigenvector.Comparison(ref cEigenvector, ref CaveB14.Eigenvector))
            {
                if (CaveB14.ContProgramme < 20)
                {
                    reference.Add(CaveB14.CaverModelNumber);
                    return reference;
                }
            }
            if (CEigenvector.Comparison(ref cEigenvector, ref CaveB15.Eigenvector))
            {
                if (CaveB15.ContProgramme < 20)
                {
                    reference.Add(CaveB15.CaverModelNumber);
                    return reference;
                }
            }
            //B2
            if (CEigenvector.Comparison(ref cEigenvector, ref CaveB21.Eigenvector))
            {
                if (CaveB21.ContProgramme < 20)
                {
                    reference.Add(CaveB21.CaverModelNumber);
                    return reference;
                }
            }
            if (CEigenvector.Comparison(ref cEigenvector, ref CaveB22.Eigenvector))
            {
                if (CaveB22.ContProgramme < 20)
                {
                    reference.Add(CaveB22.CaverModelNumber);
                    return reference;
                }
            }
            if (CEigenvector.Comparison(ref cEigenvector, ref CaveB23.Eigenvector))
            {
                if (CaveB23.ContProgramme < 20)
                {
                    reference.Add(CaveB23.CaverModelNumber);
                    return reference;
                }
            }
            if (CEigenvector.Comparison(ref cEigenvector, ref CaveB24.Eigenvector))
            {
                if (CaveB24.ContProgramme < 20)
                {
                    reference.Add(CaveB24.CaverModelNumber);
                    return reference;
                }
            }
            if (CEigenvector.Comparison(ref cEigenvector, ref CaveB25.Eigenvector))
            {
                if (CaveB25.ContProgramme < 20)
                {
                    reference.Add(CaveB25.CaverModelNumber);
                    return reference;
                }
            }
            //B2
            if (CEigenvector.Comparison(ref cEigenvector, ref CaveB31.Eigenvector))
            {
                if (CaveB31.ContProgramme < 20)
                {
                    reference.Add(CaveB31.CaverModelNumber);
                    return reference;
                }
            }
            if (CEigenvector.Comparison(ref cEigenvector, ref CaveB32.Eigenvector))
            {
                if (CaveB32.ContProgramme < 20)
                {
                    reference.Add(CaveB32.CaverModelNumber);
                    return reference;
                }
            }
            if (CEigenvector.Comparison(ref cEigenvector, ref CaveB33.Eigenvector))
            {
                if (CaveB33.ContProgramme < 20)
                {
                    reference.Add(CaveB33.CaverModelNumber);
                    return reference;
                }
            }
            if (CEigenvector.Comparison(ref cEigenvector, ref CaveB34.Eigenvector))
            {
                if (CaveB34.ContProgramme < 20)
                {
                    reference.Add(CaveB34.CaverModelNumber);
                    return reference;
                }
            }
            if (CEigenvector.Comparison(ref cEigenvector, ref CaveB35.Eigenvector))
            {
                if (CaveB35.ContProgramme < 20)
                {
                    reference.Add(CaveB35.CaverModelNumber);
                    return reference;
                }
            }

            #endregion 收索分类区内相同类型仓的坐标
            //cEigenvector = new CEigenvector(LINE.ZERO, "", KCAndBF.ZERO, Remark.ZERO);
            return reference;
        }

        static object SearchClassReferenceARow1Lock = new object();
        /// <summary>
        /// 搜索分类区A边第一排内同类坐标
        /// </summary>
        /// <param name="cEigenvector"></param>
        /// <returns></returns>
        public static List<int> SearchClassReferenceARow1(ref CEigenvector cEigenvector)
        {
            lock (SearchClassReferenceARow1Lock)
            {
                List<int> reference = new List<int>();
                //A1
                if (CEigenvector.Comparison(ref cEigenvector, ref CaveA11.Eigenvector))
                {
                    if (CaveA11.ContProgramme < 20)
                    {
                        reference.Add(CaveA11.CaverModelNumber);
                        return reference;
                    }
                }
                if (CEigenvector.Comparison(ref cEigenvector, ref CaveA12.Eigenvector))
                {
                    if (CaveA12.ContProgramme < 20)
                    {
                        reference.Add(CaveA12.CaverModelNumber);
                        return reference;
                    }
                }
                if (CEigenvector.Comparison(ref cEigenvector, ref CaveA13.Eigenvector))
                {
                    if (CaveA13.ContProgramme < 20)
                    {
                        reference.Add(CaveA13.CaverModelNumber);
                        return reference;
                    }
                }
                if (CEigenvector.Comparison(ref cEigenvector, ref CaveA14.Eigenvector))
                {
                    if (CaveA14.ContProgramme < 20)
                    {
                        reference.Add(CaveA14.CaverModelNumber);
                        return reference;
                    }
                }
                if (CEigenvector.Comparison(ref cEigenvector, ref CaveA15.Eigenvector))
                {
                    if (CaveA15.ContProgramme < 20)
                    {
                        reference.Add(CaveA15.CaverModelNumber);
                        return reference;
                    }
                }
                //cEigenvector = new CEigenvector(LINE.ZERO, "", KCAndBF.ZERO, Remark.ZERO);
                return reference;
            }

        }

        /// <summary>
        /// 搜索分类区A边第一排内同类坐标
        /// </summary>
        /// <param name="cEigenvector"></param>
        /// <returns></returns>
        public static List<int> SearchClassReferenceBRow1(ref CEigenvector cEigenvector)
        {
            List<int> reference = new List<int>();
            //B1
            if (CEigenvector.Comparison(ref cEigenvector, ref CaveB11.Eigenvector))
            {
                if (CaveB11.ContProgramme < 20)
                {
                    reference.Add(CaveB11.CaverModelNumber);
                    return reference;
                }
            }
            if (CEigenvector.Comparison(ref cEigenvector, ref CaveB12.Eigenvector))
            {
                if (CaveB12.ContProgramme < 20)
                {
                    reference.Add(CaveB12.CaverModelNumber);
                    return reference;
                }
            }
            if (CEigenvector.Comparison(ref cEigenvector, ref CaveB13.Eigenvector))
            {
                if (CaveB13.ContProgramme < 20)
                {
                    reference.Add(CaveB13.CaverModelNumber);
                    return reference;
                }
            }
            if (CEigenvector.Comparison(ref cEigenvector, ref CaveB14.Eigenvector))
            {
                if (CaveB14.ContProgramme < 20)
                {
                    reference.Add(CaveB14.CaverModelNumber);
                    return reference;
                }
            }
            if (CEigenvector.Comparison(ref cEigenvector, ref CaveB15.Eigenvector))
            {
                if (CaveB15.ContProgramme < 20)
                {
                    reference.Add(CaveB15.CaverModelNumber);
                    return reference;
                }
            }
            //cEigenvector = new CEigenvector(LINE.ZERO, "", KCAndBF.ZERO, Remark.ZERO);
            return reference;
        }
        static object SearchClassReferenceARow2Lock = new object();
        /// <summary>
        /// 搜索分类区A边第二排内同类坐标
        /// </summary>
        /// <param name="cEigenvector"></param>
        /// <returns></returns>
        public static List<int> SearchClassReferenceARow2(ref CEigenvector cEigenvector)
        {
            lock (SearchClassReferenceARow2Lock)
            {
                List<int> reference = new List<int>();
                //A2
                if (CEigenvector.Comparison(ref cEigenvector, ref CaveA21.Eigenvector))
                {
                    if (CaveA21.ContProgramme < 20)
                    {
                        reference.Add(CaveA21.CaverModelNumber);
                        return reference;
                    }
                }
                if (CEigenvector.Comparison(ref cEigenvector, ref CaveA22.Eigenvector))
                {
                    if (CaveA22.ContProgramme < 20)
                    {
                        reference.Add(CaveA22.CaverModelNumber);
                        return reference;
                    }
                }
                if (CEigenvector.Comparison(ref cEigenvector, ref CaveA23.Eigenvector))
                {
                    if (CaveA23.ContProgramme < 20)
                    {
                        reference.Add(CaveA23.CaverModelNumber);
                        return reference;
                    }
                }
                if (CEigenvector.Comparison(ref cEigenvector, ref CaveA24.Eigenvector))
                {
                    if (CaveA24.ContProgramme < 20)
                    {
                        reference.Add(CaveA24.CaverModelNumber);
                        return reference;
                    }
                }
                if (CEigenvector.Comparison(ref cEigenvector, ref CaveA25.Eigenvector))
                {
                    if (CaveA25.ContProgramme < 20)
                    {
                        reference.Add(CaveA25.CaverModelNumber);
                        return reference;
                    }
                }
                //cEigenvector = new CEigenvector(LINE.ZERO, "", KCAndBF.ZERO, Remark.ZERO);
                return reference;
            }

        }

        /// <summary>
        /// 搜索分类区B边第二排内同类坐标
        /// </summary>
        /// <param name="cEigenvector"></param>
        /// <returns></returns>
        public static List<int> SearchClassReferenceBRow2(ref CEigenvector cEigenvector)
        {
            List<int> reference = new List<int>();
            //A2
            if (CEigenvector.Comparison(ref cEigenvector, ref CaveB21.Eigenvector))
            {
                if (CaveB21.ContProgramme < 20)
                {
                    reference.Add(CaveB21.CaverModelNumber);
                    return reference;
                }
            }
            if (CEigenvector.Comparison(ref cEigenvector, ref CaveB22.Eigenvector))
            {
                if (CaveB22.ContProgramme < 20)
                {
                    reference.Add(CaveB22.CaverModelNumber);
                    return reference;
                }
            }
            if (CEigenvector.Comparison(ref cEigenvector, ref CaveB23.Eigenvector))
            {
                if (CaveB23.ContProgramme < 20)
                {
                    reference.Add(CaveB23.CaverModelNumber);
                    return reference;
                }
            }
            if (CEigenvector.Comparison(ref cEigenvector, ref CaveB24.Eigenvector))
            {
                if (CaveB24.ContProgramme < 20)
                {
                    reference.Add(CaveB24.CaverModelNumber);
                    return reference;
                }
            }
            if (CEigenvector.Comparison(ref cEigenvector, ref CaveB25.Eigenvector))
            {
                if (CaveB25.ContProgramme < 20)
                {
                    reference.Add(CaveB25.CaverModelNumber);
                    return reference;
                }
            }
            //cEigenvector = new CEigenvector(LINE.ZERO, "", KCAndBF.ZERO, Remark.ZERO);
            return reference;
        }
        static object SearchClassReferenceARow3Lock = new object();
        /// <summary>
        /// 搜索分类区A边第三排内同类坐标
        /// </summary>
        /// <param name="cEigenvector"></param>
        /// <returns></returns>
        public static List<int> SearchClassReferenceARow3(ref CEigenvector cEigenvector)
        {
            lock (SearchClassReferenceARow3Lock)
            {
                List<int> reference = new List<int>();
                //A3
                if (CEigenvector.Comparison(ref cEigenvector, ref CaveA31.Eigenvector))
                {
                    if (CaveA31.ContProgramme < 20)
                    {
                        reference.Add(CaveA31.CaverModelNumber);
                        return reference;
                    }
                }
                if (CEigenvector.Comparison(ref cEigenvector, ref CaveA32.Eigenvector))
                {
                    if (CaveA32.ContProgramme < 20)
                    {
                        reference.Add(CaveA32.CaverModelNumber);
                        return reference;
                    }
                }
                if (CEigenvector.Comparison(ref cEigenvector, ref CaveA33.Eigenvector))
                {
                    if (CaveA33.ContProgramme < 20)
                    {
                        reference.Add(CaveA33.CaverModelNumber);
                        return reference;
                    }
                }
                if (CEigenvector.Comparison(ref cEigenvector, ref CaveA34.Eigenvector))
                {
                    if (CaveA34.ContProgramme < 20)
                    {
                        reference.Add(CaveA34.CaverModelNumber);
                        return reference;
                    }
                }
                if (CEigenvector.Comparison(ref cEigenvector, ref CaveA35.Eigenvector))
                {
                    if (CaveA35.ContProgramme < 20)
                    {
                        reference.Add(CaveA35.CaverModelNumber);
                        return reference;
                    }
                }
                //cEigenvector = new CEigenvector(LINE.ZERO, "", KCAndBF.ZERO, Remark.ZERO);
                return reference;
            }

        }

        /// <summary>
        /// 搜索分类区B边第三排内同类坐标
        /// </summary>
        /// <param name="cEigenvector"></param>
        /// <returns></returns>
        public static List<int> SearchClassReferenceBRow3(ref CEigenvector cEigenvector)
        {
            List<int> reference = new List<int>();
            //B3
            if (CEigenvector.Comparison(ref cEigenvector, ref CaveB31.Eigenvector))
            {
                if (CaveB31.ContProgramme < 20)
                {
                    reference.Add(CaveB31.CaverModelNumber);
                    return reference;
                }
            }
            if (CEigenvector.Comparison(ref cEigenvector, ref CaveB32.Eigenvector))
            {
                if (CaveB32.ContProgramme < 20)
                {
                    reference.Add(CaveB32.CaverModelNumber);
                    return reference;
                }
            }
            if (CEigenvector.Comparison(ref cEigenvector, ref CaveB33.Eigenvector))
            {
                if (CaveB33.ContProgramme < 20)
                {
                    reference.Add(CaveB33.CaverModelNumber);
                    return reference;
                }
            }
            if (CEigenvector.Comparison(ref cEigenvector, ref CaveB34.Eigenvector))
            {
                if (CaveB34.ContProgramme < 20)
                {
                    reference.Add(CaveB34.CaverModelNumber);
                    return reference;
                }
            }
            if (CEigenvector.Comparison(ref cEigenvector, ref CaveB35.Eigenvector))
            {
                if (CaveB35.ContProgramme < 20)
                {
                    reference.Add(CaveB35.CaverModelNumber);
                    return reference;
                }
            }
            //cEigenvector = new CEigenvector(LINE.ZERO, "", KCAndBF.ZERO, Remark.ZERO);
            return reference;
        }
        static object SearchVacancyARow1Lock = new object();
        /// <summary>
        /// 搜索分类区A边第一排内空仓坐标
        /// </summary>
        /// <returns></returns>
        public static List<int> SearchVacancyARow1()
        {
            lock (SearchVacancyARow1Lock)
            {
                List<int> reference = new List<int>();
                if (CaveA11.Eigenvector.PN == "" && CaveA11.ContProgramme == 0)
                {
                    reference.Add(CaveA11.CaverModelNumber);
                    return reference;
                }
                if (CaveA12.Eigenvector.PN == "" && CaveA12.ContProgramme == 0)
                {
                    reference.Add(CaveA12.CaverModelNumber);
                    return reference;
                }
                if (CaveA13.Eigenvector.PN == "" && CaveA13.ContProgramme == 0)
                {
                    reference.Add(CaveA13.CaverModelNumber);
                    return reference;
                }
                if (CaveA14.Eigenvector.PN == "" && CaveA14.ContProgramme == 0)
                {
                    reference.Add(CaveA14.CaverModelNumber);
                    return reference;
                }
                if (CaveA15.Eigenvector.PN == "" && CaveA15.ContProgramme == 0)
                {
                    reference.Add(CaveA15.CaverModelNumber);
                    return reference;
                }
                return reference;
            }

        }

        /// <summary>
        /// 搜索分类区B边第一排内空仓坐标
        /// </summary>
        /// <returns></returns>
        public static List<int> SearchVacancyBRow1()
        {
            List<int> reference = new List<int>();
            if (CaveB11.Eigenvector.PN == "" && CaveB11.ContProgramme == 0)
            {
                reference.Add(CaveB11.CaverModelNumber);
                return reference;
            }
            if (CaveB12.Eigenvector.PN == "" && CaveB12.ContProgramme == 0)
            {
                reference.Add(CaveB12.CaverModelNumber);
                return reference;
            }
            if (CaveB13.Eigenvector.PN == "" && CaveB13.ContProgramme == 0)
            {
                reference.Add(CaveB13.CaverModelNumber);
                return reference;
            }
            if (CaveB14.Eigenvector.PN == "" && CaveB14.ContProgramme == 0)
            {
                reference.Add(CaveB14.CaverModelNumber);
                return reference;
            }
            if (CaveB15.Eigenvector.PN == "" && CaveB15.ContProgramme == 0)
            {
                reference.Add(CaveB15.CaverModelNumber);
                return reference;
            }
            return reference;
        }
        static object SearchVacancyARow2Lock = new object();
        /// <summary>
        /// 搜索分类区A边第二排内空仓坐标
        /// </summary>
        /// <returns></returns>
        public static List<int> SearchVacancyARow2()
        {
            lock (SearchVacancyARow2Lock)
            {
                List<int> reference = new List<int>();
                if (CaveA21.Eigenvector.PN == "" && CaveA21.ContProgramme == 0)
                {
                    reference.Add(CaveA21.CaverModelNumber);
                    return reference;
                }
                if (CaveA22.Eigenvector.PN == "" && CaveA22.ContProgramme == 0)
                {
                    reference.Add(CaveA22.CaverModelNumber);
                    return reference;
                }
                if (CaveA23.Eigenvector.PN == "" && CaveA23.ContProgramme == 0)
                {
                    reference.Add(CaveA23.CaverModelNumber);
                    return reference;
                }
                if (CaveA24.Eigenvector.PN == "" && CaveA24.ContProgramme == 0)
                {
                    reference.Add(CaveA24.CaverModelNumber);
                    return reference;
                }
                if (CaveA25.Eigenvector.PN == "" && CaveA25.ContProgramme == 0)
                {
                    reference.Add(CaveA25.CaverModelNumber);
                    return reference;
                }
                return reference;
            }
            
        }

        /// <summary>
        /// 搜索分类区B边第二排内空仓坐标
        /// </summary>
        /// <returns></returns>
        public static List<int> SearchVacancyBRow2()
        {
            List<int> reference = new List<int>();
            if (CaveB21.Eigenvector.PN == "" && CaveB21.ContProgramme == 0)
            {
                reference.Add(CaveB21.CaverModelNumber);
                return reference;
            }
            if (CaveB22.Eigenvector.PN == "" && CaveB22.ContProgramme == 0)
            {
                reference.Add(CaveB22.CaverModelNumber);
                return reference;
            }
            if (CaveB23.Eigenvector.PN == "" && CaveB23.ContProgramme == 0)
            {
                reference.Add(CaveB23.CaverModelNumber);
                return reference;
            }
            if (CaveB24.Eigenvector.PN == "" && CaveB24.ContProgramme == 0)
            {
                reference.Add(CaveB24.CaverModelNumber);
                return reference;
            }
            if (CaveB25.Eigenvector.PN == "" && CaveB25.ContProgramme == 0)
            {
                reference.Add(CaveB25.CaverModelNumber);
                return reference;
            }
            return reference;
        }
        static object SearchVacancyARow3Lock = new object();
        /// <summary>
        /// 搜索分类区A边第三排内空仓坐标
        /// </summary>
        /// <returns></returns>
        public static List<int> SearchVacancyARow3()
        {
            lock (SearchVacancyARow3Lock)
            {
                List<int> reference = new List<int>();
                if (CaveA31.Eigenvector.PN == "" && CaveA31.ContProgramme == 0)
                {
                    reference.Add(CaveA31.CaverModelNumber);
                    return reference;
                }
                if (CaveA32.Eigenvector.PN == "" && CaveA32.ContProgramme == 0)
                {
                    reference.Add(CaveA32.CaverModelNumber);
                    return reference;
                }
                if (CaveA33.Eigenvector.PN == "" && CaveA33.ContProgramme == 0)
                {
                    reference.Add(CaveA33.CaverModelNumber);
                    return reference;
                }
                if (CaveA34.Eigenvector.PN == "" && CaveA34.ContProgramme == 0)
                {
                    reference.Add(CaveA34.CaverModelNumber);
                    return reference;
                }
                if (CaveA35.Eigenvector.PN == "" && CaveA35.ContProgramme == 0)
                {
                    reference.Add(CaveA35.CaverModelNumber);
                    return reference;
                }
                return reference;
            }

        }

        /// <summary>
        /// 搜索分类区B边第三排内空仓坐标
        /// </summary>
        /// <returns></returns>
        public static List<int> SearchVacancyBRow3()
        {
            List<int> reference = new List<int>();
            if (CaveB31.Eigenvector.PN == "" && CaveB31.ContProgramme == 0)
            {
                reference.Add(CaveB31.CaverModelNumber);
                return reference;
            }
            if (CaveB32.Eigenvector.PN == "" && CaveB32.ContProgramme == 0)
            {
                reference.Add(CaveB32.CaverModelNumber);
                return reference;
            }
            if (CaveB33.Eigenvector.PN == "" && CaveB33.ContProgramme == 0)
            {
                reference.Add(CaveB33.CaverModelNumber);
                return reference;
            }
            if (CaveB34.Eigenvector.PN == "" && CaveB34.ContProgramme == 0)
            {
                reference.Add(CaveB34.CaverModelNumber);
                return reference;
            }
            if (CaveB35.Eigenvector.PN == "" && CaveB35.ContProgramme == 0)
            {
                reference.Add(CaveB35.CaverModelNumber);
                return reference;
            }
            return reference;
        }

        /// <summary>
        /// 对应的仓坐标，的入仓操作
        /// </summary>
        /// <param name="num"></param>
        /// <param name="sna"></param>
        /// <param name="snb"></param>
        public static void CaverModelNumber_ProgrammeWarehousing(int num, string sna, string snb, ref byte flag)
        {
            switch (num)
            {
                //
                case 111:
                    Caver.CaveA11.ProgrammeWarehousing(sna, snb, ref flag);
                    break;

                case 112:
                    Caver.CaveA12.ProgrammeWarehousing(sna, snb, ref flag);
                    break;

                case 113:
                    Caver.CaveA13.ProgrammeWarehousing(sna, snb, ref flag);
                    break;

                case 114:
                    Caver.CaveA14.ProgrammeWarehousing(sna, snb, ref flag);
                    break;

                case 115:
                    Caver.CaveA15.ProgrammeWarehousing(sna, snb, ref flag);
                    break;
                //
                case 121:
                    Caver.CaveA21.ProgrammeWarehousing(sna, snb, ref flag);
                    break;

                case 122:
                    Caver.CaveA22.ProgrammeWarehousing(sna, snb, ref flag);
                    break;

                case 123:
                    Caver.CaveA23.ProgrammeWarehousing(sna, snb, ref flag);
                    break;

                case 124:
                    Caver.CaveA24.ProgrammeWarehousing(sna, snb, ref flag);
                    break;

                case 125:
                    Caver.CaveA25.ProgrammeWarehousing(sna, snb, ref flag);
                    break;
                //
                case 131:
                    Caver.CaveA31.ProgrammeWarehousing(sna, snb, ref flag);
                    break;

                case 132:
                    Caver.CaveA32.ProgrammeWarehousing(sna, snb, ref flag);
                    break;

                case 133:
                    Caver.CaveA33.ProgrammeWarehousing(sna, snb, ref flag);
                    break;

                case 134:
                    Caver.CaveA34.ProgrammeWarehousing(sna, snb, ref flag);
                    break;

                case 135:
                    Caver.CaveA35.ProgrammeWarehousing(sna, snb, ref flag);
                    break;

                case 211:
                    Caver.CaveB11.ProgrammeWarehousing(sna, snb, ref flag);
                    break;

                case 212:
                    Caver.CaveB12.ProgrammeWarehousing(sna, snb, ref flag);
                    break;

                case 213:
                    Caver.CaveB13.ProgrammeWarehousing(sna, snb, ref flag);
                    break;

                case 214:
                    Caver.CaveB14.ProgrammeWarehousing(sna, snb, ref flag);
                    break;

                case 215:
                    Caver.CaveB15.ProgrammeWarehousing(sna, snb, ref flag);
                    break;
                //
                case 221:
                    Caver.CaveB21.ProgrammeWarehousing(sna, snb, ref flag);
                    break;

                case 222:
                    Caver.CaveB22.ProgrammeWarehousing(sna, snb, ref flag);
                    break;

                case 223:
                    Caver.CaveB23.ProgrammeWarehousing(sna, snb, ref flag);
                    break;

                case 224:
                    Caver.CaveB24.ProgrammeWarehousing(sna, snb, ref flag);
                    break;

                case 225:
                    Caver.CaveB25.ProgrammeWarehousing(sna, snb, ref flag);
                    break;
                //
                case 231:
                    Caver.CaveB31.ProgrammeWarehousing(sna, snb, ref flag);
                    break;

                case 232:
                    Caver.CaveB32.ProgrammeWarehousing(sna, snb, ref flag);
                    break;

                case 233:
                    Caver.CaveB33.ProgrammeWarehousing(sna, snb, ref flag);
                    break;

                case 234:
                    Caver.CaveB34.ProgrammeWarehousing(sna, snb, ref flag);
                    break;

                case 235:
                    Caver.CaveB35.ProgrammeWarehousing(sna, snb, ref flag);
                    break;

                default:
                    break;
            }
        }
        /// <summary>
        /// 对应的仓坐标，的入仓操作
        /// </summary>
        /// <param name="num"></param>
        /// <param name="sna"></param>
        /// <param name="snb"></param>
        public static void CaverModelNumber_ProgrammeWarehousing_(int num, string sna, string snb)
        {
            switch (num)
            {
                //
                case 111:
                    Caver.CaveA11.ProgrammeWarehousing_(sna, snb);
                    break;

                case 112:
                    Caver.CaveA12.ProgrammeWarehousing_(sna, snb);
                    break;

                case 113:
                    Caver.CaveA13.ProgrammeWarehousing_(sna, snb);
                    break;

                case 114:
                    Caver.CaveA14.ProgrammeWarehousing_(sna, snb);
                    break;

                case 115:
                    Caver.CaveA15.ProgrammeWarehousing_(sna, snb);
                    break;
                //
                case 121:
                    Caver.CaveA21.ProgrammeWarehousing_(sna, snb);
                    break;

                case 122:
                    Caver.CaveA22.ProgrammeWarehousing_(sna, snb);
                    break;

                case 123:
                    Caver.CaveA23.ProgrammeWarehousing_(sna, snb);
                    break;

                case 124:
                    Caver.CaveA24.ProgrammeWarehousing_(sna, snb);
                    break;

                case 125:
                    Caver.CaveA25.ProgrammeWarehousing_(sna, snb);
                    break;
                //
                case 131:
                    Caver.CaveA31.ProgrammeWarehousing_(sna, snb);
                    break;

                case 132:
                    Caver.CaveA32.ProgrammeWarehousing_(sna, snb);
                    break;

                case 133:
                    Caver.CaveA33.ProgrammeWarehousing_(sna, snb);
                    break;

                case 134:
                    Caver.CaveA34.ProgrammeWarehousing_(sna, snb);
                    break;

                case 135:
                    Caver.CaveA35.ProgrammeWarehousing_(sna, snb);
                    break;

                case 211:
                    Caver.CaveB11.ProgrammeWarehousing_(sna, snb);
                    break;

                case 212:
                    Caver.CaveB12.ProgrammeWarehousing_(sna, snb);
                    break;

                case 213:
                    Caver.CaveB13.ProgrammeWarehousing_(sna, snb);
                    break;

                case 214:
                    Caver.CaveB14.ProgrammeWarehousing_(sna, snb);
                    break;

                case 215:
                    Caver.CaveB15.ProgrammeWarehousing_(sna, snb);
                    break;
                //
                case 221:
                    Caver.CaveB21.ProgrammeWarehousing_(sna, snb);
                    break;

                case 222:
                    Caver.CaveB22.ProgrammeWarehousing_(sna, snb);
                    break;

                case 223:
                    Caver.CaveB23.ProgrammeWarehousing_(sna, snb);
                    break;

                case 224:
                    Caver.CaveB24.ProgrammeWarehousing_(sna, snb);
                    break;

                case 225:
                    Caver.CaveB25.ProgrammeWarehousing_(sna, snb);
                    break;
                //
                case 231:
                    Caver.CaveB31.ProgrammeWarehousing_(sna, snb);
                    break;

                case 232:
                    Caver.CaveB32.ProgrammeWarehousing_(sna, snb);
                    break;

                case 233:
                    Caver.CaveB33.ProgrammeWarehousing_(sna, snb);
                    break;

                case 234:
                    Caver.CaveB34.ProgrammeWarehousing_(sna, snb);
                    break;

                case 235:
                    Caver.CaveB35.ProgrammeWarehousing_(sna, snb);
                    break;

                default:
                    break;
            }
        }

        /// <summary>
        /// 修改对应仓坐标的仓的特征
        /// </summary>
        /// <param name="num"></param>
        /// <param name="cEigenvector"></param>
        public static void CaverModelNumber_Eigenvector(int num, ref CEigenvector cEigenvector)
        {
            switch (num)
            {
                //
                case 111:
                    Caver.CaveA11.Eigenvector = new CEigenvector(cEigenvector.LINEi, cEigenvector.PN, cEigenvector.KCAndBF, cEigenvector.Remark, cEigenvector.MEigenvector);
                    break;

                case 112:
                    Caver.CaveA12.Eigenvector = new CEigenvector(cEigenvector.LINEi, cEigenvector.PN, cEigenvector.KCAndBF, cEigenvector.Remark, cEigenvector.MEigenvector);
                    break;

                case 113:
                    Caver.CaveA13.Eigenvector = new CEigenvector(cEigenvector.LINEi, cEigenvector.PN, cEigenvector.KCAndBF, cEigenvector.Remark, cEigenvector.MEigenvector);
                    break;

                case 114:
                    Caver.CaveA14.Eigenvector = new CEigenvector(cEigenvector.LINEi, cEigenvector.PN, cEigenvector.KCAndBF, cEigenvector.Remark, cEigenvector.MEigenvector);
                    break;

                case 115:
                    Caver.CaveA15.Eigenvector = new CEigenvector(cEigenvector.LINEi, cEigenvector.PN, cEigenvector.KCAndBF, cEigenvector.Remark, cEigenvector.MEigenvector);
                    break;
                //
                case 121:
                    Caver.CaveA21.Eigenvector = new CEigenvector(cEigenvector.LINEi, cEigenvector.PN, cEigenvector.KCAndBF, cEigenvector.Remark, cEigenvector.MEigenvector);
                    break;

                case 122:
                    Caver.CaveA22.Eigenvector = new CEigenvector(cEigenvector.LINEi, cEigenvector.PN, cEigenvector.KCAndBF, cEigenvector.Remark, cEigenvector.MEigenvector);
                    break;

                case 123:
                    Caver.CaveA23.Eigenvector = new CEigenvector(cEigenvector.LINEi, cEigenvector.PN, cEigenvector.KCAndBF, cEigenvector.Remark, cEigenvector.MEigenvector);
                    break;

                case 124:
                    Caver.CaveA24.Eigenvector = new CEigenvector(cEigenvector.LINEi, cEigenvector.PN, cEigenvector.KCAndBF, cEigenvector.Remark, cEigenvector.MEigenvector);
                    break;

                case 125:
                    Caver.CaveA25.Eigenvector = new CEigenvector(cEigenvector.LINEi, cEigenvector.PN, cEigenvector.KCAndBF, cEigenvector.Remark, cEigenvector.MEigenvector);
                    break;
                //
                case 131:
                    Caver.CaveA31.Eigenvector = new CEigenvector(cEigenvector.LINEi, cEigenvector.PN, cEigenvector.KCAndBF, cEigenvector.Remark, cEigenvector.MEigenvector);
                    break;

                case 132:
                    Caver.CaveA32.Eigenvector = new CEigenvector(cEigenvector.LINEi, cEigenvector.PN, cEigenvector.KCAndBF, cEigenvector.Remark, cEigenvector.MEigenvector);
                    break;

                case 133:
                    Caver.CaveA33.Eigenvector = new CEigenvector(cEigenvector.LINEi, cEigenvector.PN, cEigenvector.KCAndBF, cEigenvector.Remark, cEigenvector.MEigenvector);
                    break;

                case 134:
                    Caver.CaveA34.Eigenvector = new CEigenvector(cEigenvector.LINEi, cEigenvector.PN, cEigenvector.KCAndBF, cEigenvector.Remark, cEigenvector.MEigenvector);
                    break;

                case 135:
                    Caver.CaveA35.Eigenvector = new CEigenvector(cEigenvector.LINEi, cEigenvector.PN, cEigenvector.KCAndBF, cEigenvector.Remark, cEigenvector.MEigenvector);
                    break;

                //
                case 211:
                    Caver.CaveB11.Eigenvector = new CEigenvector(cEigenvector.LINEi, cEigenvector.PN, cEigenvector.KCAndBF, cEigenvector.Remark, cEigenvector.MEigenvector);
                    break;

                case 212:
                    Caver.CaveB12.Eigenvector = new CEigenvector(cEigenvector.LINEi, cEigenvector.PN, cEigenvector.KCAndBF, cEigenvector.Remark, cEigenvector.MEigenvector);
                    break;

                case 213:
                    Caver.CaveB13.Eigenvector = new CEigenvector(cEigenvector.LINEi, cEigenvector.PN, cEigenvector.KCAndBF, cEigenvector.Remark, cEigenvector.MEigenvector);
                    break;

                case 214:
                    Caver.CaveB14.Eigenvector = new CEigenvector(cEigenvector.LINEi, cEigenvector.PN, cEigenvector.KCAndBF, cEigenvector.Remark, cEigenvector.MEigenvector);
                    break;

                case 215:
                    Caver.CaveB15.Eigenvector = new CEigenvector(cEigenvector.LINEi, cEigenvector.PN, cEigenvector.KCAndBF, cEigenvector.Remark, cEigenvector.MEigenvector);
                    break;
                //
                case 221:
                    Caver.CaveB21.Eigenvector = new CEigenvector(cEigenvector.LINEi, cEigenvector.PN, cEigenvector.KCAndBF, cEigenvector.Remark, cEigenvector.MEigenvector);
                    break;

                case 222:
                    Caver.CaveB22.Eigenvector = new CEigenvector(cEigenvector.LINEi, cEigenvector.PN, cEigenvector.KCAndBF, cEigenvector.Remark, cEigenvector.MEigenvector);
                    break;

                case 223:
                    Caver.CaveB23.Eigenvector = new CEigenvector(cEigenvector.LINEi, cEigenvector.PN, cEigenvector.KCAndBF, cEigenvector.Remark, cEigenvector.MEigenvector);
                    break;

                case 224:
                    Caver.CaveB24.Eigenvector = new CEigenvector(cEigenvector.LINEi, cEigenvector.PN, cEigenvector.KCAndBF, cEigenvector.Remark, cEigenvector.MEigenvector);
                    break;

                case 225:
                    Caver.CaveB25.Eigenvector = new CEigenvector(cEigenvector.LINEi, cEigenvector.PN, cEigenvector.KCAndBF, cEigenvector.Remark, cEigenvector.MEigenvector);
                    break;
                //
                case 231:
                    Caver.CaveB31.Eigenvector = new CEigenvector(cEigenvector.LINEi, cEigenvector.PN, cEigenvector.KCAndBF, cEigenvector.Remark, cEigenvector.MEigenvector);
                    break;

                case 232:
                    Caver.CaveB32.Eigenvector = new CEigenvector(cEigenvector.LINEi, cEigenvector.PN, cEigenvector.KCAndBF, cEigenvector.Remark, cEigenvector.MEigenvector);
                    break;

                case 233:
                    Caver.CaveB33.Eigenvector = new CEigenvector(cEigenvector.LINEi, cEigenvector.PN, cEigenvector.KCAndBF, cEigenvector.Remark, cEigenvector.MEigenvector);
                    break;

                case 234:
                    Caver.CaveB34.Eigenvector = new CEigenvector(cEigenvector.LINEi, cEigenvector.PN, cEigenvector.KCAndBF, cEigenvector.Remark, cEigenvector.MEigenvector);
                    break;

                case 235:
                    Caver.CaveB35.Eigenvector = new CEigenvector(cEigenvector.LINEi, cEigenvector.PN, cEigenvector.KCAndBF, cEigenvector.Remark, cEigenvector.MEigenvector);
                    break;

                default:
                    break;
            }
        }

        #endregion 关于仓位的相关公共方法

        #region 运行相关

        public static void CaverRuning()
        {
            CPLCControl.LAD_SetCell_(PLC.mAutoRuning_A1);
            CPLCControl.LAD_SetCell_(PLC.mAutoRuning_A2);
            CPLCControl.LAD_SetCell_(PLC.mAutoRuning_A3);
            CPLCControl.LAD_SetCell_(PLC.mAutoRuning_B1);
            CPLCControl.LAD_SetCell_(PLC.mAutoRuning_B2);
            CPLCControl.LAD_SetCell_(PLC.mAutoRuning_B3);
        }

        public static void CaverStop()
        {
            CPLCControl.LAD_ResetCell_(PLC.mAutoRuning_A1);
            CPLCControl.LAD_ResetCell_(PLC.mAutoRuning_A2);
            CPLCControl.LAD_ResetCell_(PLC.mAutoRuning_A3);
            CPLCControl.LAD_ResetCell_(PLC.mAutoRuning_B1);
            CPLCControl.LAD_ResetCell_(PLC.mAutoRuning_B2);
            CPLCControl.LAD_ResetCell_(PLC.mAutoRuning_B3);
        }

        #endregion 运行相关

        #region 全部仓的索引
        public static List<CEigenvector> CaverAEig;
        public static List<CEigenvector> CaverBEig;

        public static void CaverEigRefresh()
        {

        }
        #endregion

        #region 仓状态标签刷新
        /// <summary>
        /// A区空闲仓集合
        /// </summary>
        public static List<int> CaverLeisureA = new List<int>();
        /// <summary>
        /// B区空闲仓集合
        /// </summary>
        public static List<int> CaverLeisureB = new List<int>();
        /// <summary>
        /// 
        /// </summary>
        public static void Leisure()
        {
            //空闲标签
            CaverLeisure("A", ref CaverLeisureA);
            CaverLeisure("B", ref CaverLeisureB);
        }
        /// <summary>
        /// 空闲仓
        /// </summary>
        /// <param name="region">A/B区</param>
        /// <returns></returns>
        private static List<int> CaverLeisure(string region,ref List<int> CaverLeisureList)
        {
            CaverLeisureList = new List<int>();

            if (region == "A")
            {
                if (CaveA11.isLeisure) CaverLeisureList.Add(CaveA11.CaverModelNumber);
                if (CaveA12.isLeisure) CaverLeisureList.Add(CaveA12.CaverModelNumber);
                if (CaveA13.isLeisure) CaverLeisureList.Add(CaveA13.CaverModelNumber);
                if (CaveA14.isLeisure) CaverLeisureList.Add(CaveA14.CaverModelNumber);
                if (CaveA15.isLeisure) CaverLeisureList.Add(CaveA15.CaverModelNumber);

                if (CaveA21.isLeisure) CaverLeisureList.Add(CaveA21.CaverModelNumber);
                if (CaveA22.isLeisure) CaverLeisureList.Add(CaveA22.CaverModelNumber);
                if (CaveA23.isLeisure) CaverLeisureList.Add(CaveA23.CaverModelNumber);
                if (CaveA24.isLeisure) CaverLeisureList.Add(CaveA24.CaverModelNumber);
                if (CaveA25.isLeisure) CaverLeisureList.Add(CaveA25.CaverModelNumber);

                if (CaveA31.isLeisure) CaverLeisureList.Add(CaveA31.CaverModelNumber);
                if (CaveA32.isLeisure) CaverLeisureList.Add(CaveA32.CaverModelNumber);
                if (CaveA33.isLeisure) CaverLeisureList.Add(CaveA33.CaverModelNumber);
                if (CaveA34.isLeisure) CaverLeisureList.Add(CaveA34.CaverModelNumber);
                if (CaveA35.isLeisure) CaverLeisureList.Add(CaveA35.CaverModelNumber);
            }
            else
            {
                if (CaveB11.isLeisure) CaverLeisureList.Add(CaveB11.CaverModelNumber);
                if (CaveB12.isLeisure) CaverLeisureList.Add(CaveB12.CaverModelNumber);
                if (CaveB13.isLeisure) CaverLeisureList.Add(CaveB13.CaverModelNumber);
                if (CaveB14.isLeisure) CaverLeisureList.Add(CaveB14.CaverModelNumber);
                if (CaveB15.isLeisure) CaverLeisureList.Add(CaveB15.CaverModelNumber);
                                                               
                if (CaveB21.isLeisure) CaverLeisureList.Add(CaveB21.CaverModelNumber);
                if (CaveB22.isLeisure) CaverLeisureList.Add(CaveB22.CaverModelNumber);
                if (CaveB23.isLeisure) CaverLeisureList.Add(CaveB23.CaverModelNumber);
                if (CaveB24.isLeisure) CaverLeisureList.Add(CaveB24.CaverModelNumber);
                if (CaveB25.isLeisure) CaverLeisureList.Add(CaveB25.CaverModelNumber);
                                                               
                if (CaveB31.isLeisure) CaverLeisureList.Add(CaveB31.CaverModelNumber);
                if (CaveB32.isLeisure) CaverLeisureList.Add(CaveB32.CaverModelNumber);
                if (CaveB33.isLeisure) CaverLeisureList.Add(CaveB33.CaverModelNumber);
                if (CaveB34.isLeisure) CaverLeisureList.Add(CaveB34.CaverModelNumber);
                if (CaveB35.isLeisure) CaverLeisureList.Add(CaveB35.CaverModelNumber);
            }



            return CaverLeisureList;
        }
        #endregion

        #region 仓超时控制
        /// <summary>
        /// 启用超时的最小空仓数量
        /// </summary>
        public static int LeastLeisureNum;
        public static void OldTimeFuncStartAndStop()
        {
            if (CaverLeisureA.Count < LeastLeisureNum)
            {
                if (!CaveModel.AOldTimeFuncTrigger) Log4Net.MsgInfo("分类区空闲仓低于" + LeastLeisureNum +"，激活超时自动清仓功能");
                CaveModel.AOldTimeFuncTrigger = true;
            }
            else
            {
                CaveModel.AOldTimeFuncTrigger = false;
            }
            if (CaverLeisureB.Count < LeastLeisureNum)
            {
                if (!CaveModel.BOldTimeFuncTrigger) Log4Net.MsgInfo("分类区空闲仓低于" + LeastLeisureNum + "，激活超时自动清仓功能");
                CaveModel.BOldTimeFuncTrigger = true;
            }
            else
            {
                CaveModel.BOldTimeFuncTrigger = false;
            }
        }
        #endregion
    }


}